javajava-modulemodule-path

How to specify multiple jar files on the modulepath for java on the command line?


For the java command line tool, there is now the --module-path option as a replacement for the --class-path (or -cp) option.

With the classpath option, you can specify wildcards to include all jars in a given directory. E.g.:

java -cp "main.jar:lib/*" com.company.app.Main

Doing the same with the module path does not seem to work. Are wildcards possible there?


Solution

  • The --module-path option expects a list of directories separated by : (at least on macOS and Linux).

    From java -help:

    --module-path <module path>...
                  A : separated list of directories, each directory
                  is a directory of modules.
    

    So if there is a lib directory with all jar files, use something like this:

    java --module-path "main.jar:lib" --module mymodule/com.company.app.Main