Java using “-cp” and “-jar” together

后端 未结 4 1751
温柔的废话
温柔的废话 2021-01-18 01:04

Folks,

Earlier, I had just one jar file and the manifest was set up such that I can simply run my program as:

 java -jar MyApp.jar

4条回答
  •  半阙折子戏
    2021-01-18 01:37

    Assuming both jar files are in the same folder and com.mycompany.mypackage.App is the main application class, try this command:

    java -cp MyCore.jar;MyApp.jar com.mycompany.mypackage.App
    

    It should work for you.

    In case you insist on use of -jar switch (why?), then you need to have your manifest file modified, to add Class-Path key and specify path to all related jar files. It makes your application less flexible in case jar files are not packaged with your main app jar file.

提交回复
热议问题