​How can I reference a classpath file in the java command​?

38 Views Asked by At

It is possible to generate a classpath file during a build, for instance using the maven-dependency-plugin to create a file named classpath:

mvn dependency:build-classpath -Dmdep.outputFile=classpath

How can I then use the file when invoking java from the command line?

1

There are 1 best solutions below

0
user2515975 On

Since JDK9 the java command supports @-file arguments where the file contents are used in place of the @-file placeholder.

Example:

$ cat classpath
./clojure-1.11.1.jar:./spec.alpha-0.3.218.jar

$ java -cp @classpath clojure.main
Clojure 1.11.1
user=>