05-24-2015, 10:03 PM
Hello.
I'm trying to replace a class method's code by some other code that requires more bytes.
I couldn't find any simple way to do that and investigation led me to Javassist that allows it and looks pretty simple to implement. (Or maybe not).
The system is Win 7 SP1 x64.
It has the latest x64 JDK 8 installed (u45) and Java works fine. I kept the x86 version off the system to avoid any conflicts for this exercise).
I copied the Javassist.jar into <java-home>/jre/lib/ext (one of their suggestions other than modifying the CLASSPATH).
Then I tried one of the Javassist samples (they all gave similar errors).
e.g.
javac sample/Test.java
(this one run without errors and created a Test.class in the \Sample folder)
java sample.Test
(this one gave the errors):
C:\Tools\Javassist>java sample.Test
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: javassist/NotFoundExc
eption
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javassist.NotFoundException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
----
Is it a matter of incompatibility between Javassist and the x64 version of JDK or have I missed something important?
Has anybody tried Javassist in a similar environment without problems?
Is there some other easier way to add code to some method at the bytecode level?
Thanks in advance for any pointers.
I'm trying to replace a class method's code by some other code that requires more bytes.
I couldn't find any simple way to do that and investigation led me to Javassist that allows it and looks pretty simple to implement. (Or maybe not).
The system is Win 7 SP1 x64.
It has the latest x64 JDK 8 installed (u45) and Java works fine. I kept the x86 version off the system to avoid any conflicts for this exercise).
I copied the Javassist.jar into <java-home>/jre/lib/ext (one of their suggestions other than modifying the CLASSPATH).
Then I tried one of the Javassist samples (they all gave similar errors).
e.g.
javac sample/Test.java
(this one run without errors and created a Test.class in the \Sample folder)
java sample.Test
(this one gave the errors):
C:\Tools\Javassist>java sample.Test
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: javassist/NotFoundExc
eption
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javassist.NotFoundException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
----
Is it a matter of incompatibility between Javassist and the x64 version of JDK or have I missed something important?
Has anybody tried Javassist in a similar environment without problems?
Is there some other easier way to add code to some method at the bytecode level?
Thanks in advance for any pointers.