I'm trying to execute my JAVA
app on a Linux
OS where the necessary jars are located in a different folder. How can I execute my project using the external jars?
我正在尝试在Linux OS上执行我的JAVA应用程序,其中必要的jar位于不同的文件夹中。如何使用外部罐子执行我的项目?
project location:
$ pwd
/root/MyApp/bin
$ ls
Deletion.class
jars location:
/opt/jars/*.jar
My failed execution:
执行失败:
$ java Deletion
... NoClassDefFoundError ...
$ java -cp "/opt/jars/*.jar" Deletion
Error: Could not find or load main class Deletion
2 个解决方案
#1
When setting the class path with -cp ...
, you have to also specify the current working directory (as this is not part anymore):
使用-cp ...设置类路径时,还必须指定当前工作目录(因为这不再是部分):
java -cp ".:/opt/jars/*.jar" Deletion
#2
java -cp "location of jar file:." Deletion
java -cp“jar文件的位置:”删除
#1
When setting the class path with -cp ...
, you have to also specify the current working directory (as this is not part anymore):
使用-cp ...设置类路径时,还必须指定当前工作目录(因为这不再是部分):
java -cp ".:/opt/jars/*.jar" Deletion
#2
java -cp "location of jar file:." Deletion
java -cp“jar文件的位置:”删除