I'm trying to do something that should be pretty easy but some how I keep failing...
the idea is to take existing java class from java repository (in our case java sun) modify it a bit.. recompile the class and use the modified class in our project
the steps (I took String.java from java.lang for example)
modify String String.java by adding:
public int zzz() { return 123; }
just under the class constructors.
recompile String.java
javac -d String String.java
jar -cf the compiled files this is the the result of: jar -vtf String.jar:
0 Wed May 22 10:31:06 IDT 2013 META-INF/ 68 Wed May 22 10:31:06 IDT 2013 META-INF/MANIFEST.MF 9763 Wed May 22 10:30:44 IDT 2013 java/lang/String$1.class 1232 Wed May 22 10:26:04 IDT 2013 java/lang/String$CaseInsensitiveComparator.class 17269 Wed May 22 10:26:04 IDT 2013 java/lang/String.class
write short main class:
public class main { /** * @param args */ public static void main(java.lang.String[] args) { // TODO Auto-generated method stub java.lang.String s = new java.lang.String(" xxx "); s = s.concat("bla bla"); System.out.println(s); System.out.println(s.zzz()); } }
(I get the same behavior when trying java.lang.String and just String.)
5.compile my main.java with the modified String class
javac -Xbootclasspath/p:String.jar main.java
6.run main
java -Xbootclasspath/p:String.jar main
that gives us the following output:
myusername@machinename:~/work/sand_box$ java -Xbootclasspath/p:String.jar main
xxx bla bla
Exception in thread "main" java.lang.NoSuchMethodError: java.lang.String.<init>([CZ)V
at java.lang.Integer.toString(Integer.java:333)
at java.lang.Integer.toString(Integer.java:136)
at java.lang.String.valueOf(String.java:2948)
at java.io.PrintStream.print(PrintStream.java:597)
at java.io.PrintStream.println(PrintStream.java:736)
at main.main(main.java:12)
I can't figure out what am I doing wrong can someone please shed some light on this please?
10x to all the contributors out there.