[英]Why occurs a java.lang.NoClassDefFoundError when I use args4j in a batch built by mvn:assembly
For various experimentations, I take care of a java project in github . 对于各种实验,我将在github中处理一个Java项目。
After the Maven build, the program runs with a script bat. 在Maven构建之后,该程序将使用脚本bat运行。
Now I opened a branch because I would use the library args4j to parsing the arguments. 现在,我打开了一个分支,因为我将使用库args4j来解析参数。
The build works fine, the jars exist in the directory lib , but when I run I have this stacktrace of Exception 构建工作正常,罐子存在于目录lib中 ,但是当我运行时,我具有此Exception的stacktrace
Exception in thread "main" java.lang.NoClassDefFoundError: org/kohsuke/args4j/CmdLineException at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2625) at java.lang.Class.getMethod0(Class.java:2866) at java.lang.Class.getMethod(Class.java:1676) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486) Caused by: java.lang.ClassNotFoundException: org.kohsuke.args4j.CmdLineException at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 6 more
线程“主”中的异常java.lang.NoClassDefFoundError:org / kohsuke / args4j / CmdLineException在java.lang.Class.getDeclaredMethods0(本机方法)在java.lang.Class.privateGetDeclaredMethods(Class.java:2625) .class.getMethod0(Class.java:2866)at java.lang.Class.getMethod(Class.java:1676)at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)at sun.launcher.LauncherHelper.checkAndLoadMain( LauncherHelper.java:486)原因:java.net.URLClassLoader $ 1.run(URLClassLoader.java:366)处的java.lang.ClassNotFoundException:org.kohsuke.args4j.CmdLineException java.net.URLClassLoader $ 1.run(URLClassLoader。 sun.misc上java.lang.ClassLoader.loadClass(ClassLoader.java:425)上java.net.URLClassLoader.findClass(URLClassLoader.java:354)上java.security.AccessController.doPrivileged(本地方法)上的java:355) .Launcher $ AppClassLoader.loadClass(Launcher.java:308)at java.lang.ClassLoader.loadClass(ClassLoader.java:358)...还有6个
in bat I configured the classpath so that the args4j jar in in lib : this are the instructions of bat script 在bat中,我配置了类路径,以便lib中的args4j jar:这是bat脚本的说明
SET JAVA_DIR=C:\Program Files\Java\jdk1.7.0_80\bin\
>CUT
"%JAVA_DIR%\java" -jar ".\lib\buildCSS-1.0.jar" -cp ".\lib\" -conf "./conf/environment.properties"
I don't understand the deal of java.lang.NoClassDefFoundError . 我不理解java.lang.NoClassDefFoundError的处理。 The jar are present and linked by -cp option
该罐子存在并通过-cp选项链接
Do you have any idea (and solution), please? 请问您有什么想法(和解决方案)?
You cannot combine -jar
and -cp
arguments on the command line. 您不能在命令行上组合
-jar
和-cp
参数。 If the java
command sees -jar
it treats everything after the jarfile name as application arguments, AND it ignores any earlier classpath arguments. 如果
java
命令看到-jar
则它将jarfile名称之后的所有内容都视为应用程序参数,并且它会忽略所有较早的classpath参数。
You have two choices: 您有两种选择:
-cp
, include the main JAR in the classpath, and put the full class name for the main class on the command line. -cp
,在类路径中包含主JAR,然后在命令行上输入主类的完整类名。 -jar
, and add a "Class-Path" attribute to the main JAR's manifest file listing all of the dependencies. -jar
,并在列出所有依赖项的主JAR清单文件中添加“ Class-Path”属性。 References: 参考文献:
java
command page - explains -jar
versus -cp
java
命令页面 -解释-jar
与-cp
Note: since you are building the JAR file using Maven, there are other options; 注意:由于您正在使用Maven构建JAR文件,因此还有其他选项; for example
例如
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.