当我在编译器上运行程序时,它可以正常工作,但是当我创建jar文件时,运行jar文件时无法正确引用正在使用的maven依赖项。我不知道发生了什么事。有人可以帮忙吗?我提供了屏幕截图:
<dependency>
<groupId>org.languagetool</groupId>
<artifactId>language-en</artifactId>
<version>4.4</version>
<!--<scope>provided</scope>-->
<!--<scope>system</scope>-->
<!--<systemPath>${basedir}\src\lib\language-all-4.4.jar</systemPath>-->
</dependency>
运行时出现错误:
$ java -jar Spellcheck-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/languagetool/Language
at Spellcheck.App.main(App.java:22)`Exception in thread "main"
Caused by: java.lang.ClassNotFoundException: org.languagetool.Language
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)
... 1 more
编译器的实际输出:
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java...
Potential error at line: "speling erroor everwhere."
Did you mean: [spelling, spewing, spieling]
Potential error at line: "speling erroor everwhere."
Did you mean: [error]
Potential error at line: "speling erroor everwhere."
Did you mean: [everywhere, ever where]
Process finished with exit code 0
答案 0 :(得分:0)
您需要将language-en-4.4.jar添加到您的类路径中
在您的jar所在的文件夹中,添加一个具有依赖性的文件夹“ lib”
如果您的清单文件(Spellcheck-1.0-SNAPSHOT.jar / META-INF / MANIFEST.MF)不包含“类路径:lib / language-en-4.4.jar”,请添加类路径作为参数,并且依赖关系由“;”在Linux中或在Windows中为“:”
java -cp "/lib/language-en-4.4.jar:/lib/other.jar" -jar Spellcheck-1.0-SNAPSHOT.jar
如果您的清单文件包含类路径,则仅在不使用cp参数的情况下验证是否存在lib文件夹
java -jar Spellcheck-1.0-SNAPSHOT.jar