include external jar when running java -jar

后端 未结 2 1563
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 05:00

From my readings, when you execute a command as follows:

java -jar foo.jar

Then the main classpath is ignored, and the classpath is taken f

相关标签:
2条回答
  • 2020-11-29 05:40

    Is there a reason why you are avoiding invoking the main class like

    java -cp /usr/local/jar/foobar.jar:/some/other/path.jar com.your.main.classname
    

    ?

    This type of invocation allows you to mix absolute paths with relative paths. Put this into a shell script or batch file to avoid having to actually type or remember the full classpath to simplify things.

    0 讨论(0)
  • 2020-11-29 05:42

    You can create a folder, say lib, within the folder where you have the jar file.

    Manifest.MF contents can be:

    Main-Class: com.mastergaurav.test.app.MainClass
    Class-Path: lib/one.jar lib/two.jar
    

    Folder contents:

    mainFolder/
       * lib/one.jar
       * lib/two.jar
       * my-main.jar
    

    To execute:

    java -jar my-main.jar
    
    0 讨论(0)
提交回复
热议问题