Java execute jar which depends on other jar from c

2020-03-24 06:12发布

I have an application that uses an external jar. I used eclipse and it works fine. I export as jar from eclipse, having created a Manifest file that has as Class-Path: ./cab.v1.jar I place both jars in the same directory. I run in command line: java -jar myApp.jar

and get java.lang.NoClassDefFoundError for the classes in the cab.v1.jar (the other jar) Have also tried java -cp . -jar myApp.jar but no success. What am I doing wrong?

2条回答
SAY GOODBYE
2楼-- · 2020-03-24 06:50

If you use the -jar option the classpath is ignored. You could start the application by

java -cp jar1.jar:jar2.jar mainclass

The class path separator ':' is ';' on windows.

查看更多
别忘想泡老子
3楼-- · 2020-03-24 06:52

Using the documentation for the Manifest it does not use a ./ for relative directories. Try it just with:

Class-Path: cab.v1.jar

Note that the -cp option is ignored when using -jar.

查看更多
登录 后发表回答