0
閱讀this問題後,我已經成功地運行一個.jar文件,該文件有外部依賴定位jar文件:添加外部依賴關係,通過命令行的JAR文件
/usr/lib/jvm/java-8-jdk/bin/java -classpath /usr/local/bin/kiaragen.jar:/home/kiara/AppLab/KIARA/kiaragen/src/main/resources/org/fiware/kiara/generator/idl/templates/*:/usr/lib/jvm/java-8-jdk/jre/lib/*:/home/kiara/AppLab/KIARA/kiaragen/lib/* org.fiware.kiara.generator.kiaragen
其中在/ usr /本地/ bin/kiaragen.jar是要執行的文件。現在,我試圖運行不同版本的依賴於一個.class文件:
/home/kiara/AppLab/KIARA/IDL-Parser/target/classes/com/eprosima/idl/parser/exception/ParseException.class
添加文件到classpath:
/usr/lib/jvm/java-8-jdk/bin/java -classpath /usr/local/bin/kiaragen-0.2.0.jar:/home/kiara/AppLab/KIARA/IDL-Parser/target/classes/com/eprosima/idl/parser/exception/ParseException.class:/home/kiara/AppLab/KIARA/kiaragen/src/main/resources/org/fiware/kiara/generator/idl/templates/*:/usr/lib/jvm/java-8-jdk/jre/lib/*:/home/kiara/AppLab/KIARA/kiaragen/lib/* org.fiware.kiara.generator.kiaragen
給出了以下異常:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/eprosima/idl/parser/exception/ParseException
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: com.eprosima.idl.parser.exception.ParseException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
爲什麼?
將.jar的清單文件是和以前一樣:
$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: org.fiware.kiara.generator.kiaragen
我怎樣才能.class文件添加到類路徑?