Including all the jars in a directory within the Java classpath

前端 未结 24 3604
鱼传尺愫
鱼传尺愫 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:14

    macOS, current folder

    For Java 13 on macOS Mojave…

    If all your .jar files are in the same folder, use cd to make that your current working directory. Verify with pwd.

    For the -classpath you must first list the JAR file for your app. Using a colon character : as a delimiter, append an asterisk * to get all other JAR files within the same folder. Lastly, pass the full package name of the class with your main method.

    For example, for an app in a JAR file named my_app.jar with a main method in a class named App in a package named com.example, alongside some needed jars in the same folder:

    java -classpath my_app.jar:* com.example.App
    

提交回复
热议问题