Including all the jars in a directory within the Java classpath

前端 未结 24 3619
鱼传尺愫
鱼传尺愫 2020-11-21 04:25

Is there a way to include all the jar files within a directory in the classpath?

I\'m trying java -classpath lib/*.jar:. my.package.Program and it is no

24条回答
  •  误落风尘
    2020-11-21 05:12

    We get around this problem by deploying a main jar file myapp.jar which contains a manifest (Manifest.mf) file specifying a classpath with the other required jars, which are then deployed alongside it. In this case, you only need to declare java -jar myapp.jar when running the code.

    So if you deploy the main jar into some directory, and then put the dependent jars into a lib folder beneath that, the manifest looks like:

    Manifest-Version: 1.0
    Implementation-Title: myapp
    Implementation-Version: 1.0.1
    Class-Path: lib/dep1.jar lib/dep2.jar
    

    NB: this is platform-independent - we can use the same jars to launch on a UNIX server or on a Windows PC.

提交回复
热议问题