I am using ASM 5.2 for an example project and I want to compile the project which has as dependacy the ASM library.
The java file i am trying to compile is the following:
import java.io.FileInputStream;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import static org.objectweb.asm.Opcodes.ASM5;
public class Parser2 {
public static void main(final String args[]) throws Exception {
FileInputStream inputFile = new FileInputStream("/src/Test.class");
ClassReader reader = new ClassReader(inputFile);
GraphClass gc = new GraphClass();
reader.accept(gc, 0);
}
}
class GraphClass extends ClassVisitor {
public GraphClass() {
super(ASM5);
}
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
GraphMethod newVisitor = new GraphMethod(name);
return newVisitor;
//return super.visitMethod(access, name, desc, signature,exceptions);
}
}
class GraphMethod extends MethodVisitor{
public String MthName;
public GraphMethod(String name) {
super(ASM5);
MthName = name;
}
public void visitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor, boolean isInterface) {
System.out.println(owner + "." + MthName + " ===> " + owner + "." + name);
}
}
I compile it with
javac -classpath asm-all-5.2.jar Parser2.java
which creates the class files GraphClass.class
, GraphMethod.class
and Parser2.class
.
Then upon executing the Parser2 the following error comes up.
$ java Parser2
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.ClassVisitor
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 7 more
Why does it say it cannot find the ClassVisitor?
java version in use openjdk version "1.8.0_252"