Setting Java Classpath to Load a Class File -
I'm new to Java, and I have no doubt that to issue a different file program in a specific file . For example, I have to load MyClass located in a third party jar file, which is / mylib / MyClass.class, so I tried to turn to:
java -jar mainprog .jar -classpath "/ mylib" MyClass
but I get this error:
Thread exceptions "main" java.lang.NoClassDefFoundError: MyClass due to: MyClass on java.net.URLClassLoader $ 1.run (URLClassLoader.java:221) on java.security.AccessController.doPrivileged (Native method) for Java: java.lang.ClassNotFoundException. On net.URLClassLoader.findClass java.lang.ClassLoader.loadClass (ClassLoader.java:324) to (URLClassLoader.java:209) sun.misc.Launcher $ AppClassLoader.loadClass (Launcher.java:294) on java.lang.ClassLoader Cloud Loader on Java .lang.ClassLoader.loadClassInternal (ClassLoader.java:337)
What am I doing wrong?
Text after "div class =" itemprop = "text">
When you use "- jar"
, only class-path
attribute is defined in the
file Classpath Will affect jar
INF mETA inside the file / MANIFEST.MF
This will also ignore the MyClass
argument (or more specifically): the form of an argument for the main category defined in MANIFEST.MF
Explain in.
If you want to call a class with that jar like this:
java -cp mainprog.jar: / mylib MyClass // You can use it on windows: java-cp mainprog.jar; / mylib MyClass
Comments
Post a Comment