For my current purposes I have a Maven project which creates a war
file, and I want to see what actual classpath it is using when creating the war
. Is there a way to do that in a single command -- without having to compile the entire project?
One idea is to have Maven generate the target/classpath.properties
file and then stop at that point.
As ecerulm noted in his comment to Janik's answer, you may want to specify the scope to
dependency:build-classpath
, as classpath output will differ for different scopes (by defaulttest
is used for some reason). I've ended up with a command like this:Within the POM, it could be used like this:
This will output 2 versions of classpath, one for main build and the other for tests.
or call "mvn -e -X ...." and check the output...
To get the classpath all by itself in a file, you can:
Or add this to the POM.XML:
From: http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
The command
mvn dependency:list
will list the classpath with all the jars used for compilation, runtime and test in the following format:The only requirement is that the compilation is finished. It doesn't work if the compilation isn't ran.
An other command is The command
mvn dependency:tree
.This command outputs the classpath on Mac and Linux:
Having the result printed and not saved into a file might be useful, for instance, when assigning the result to a variable in a Bash script. This solution runs on Mac and Linux only, but so do Bash shell scripts.
In Windows (e.g. in BAT files), where there is no
echo
executable, you will need something like this (untested):Alternatively, you can just execute
java
program with the classpath:Or even like that (it will use the correct classpath automatically):
However, both these alternative approaches suffer from Maven adding its error messages when your program fails.
This is a single command solution but does compile the code.
Shell script example usage
I used a variation of it in a shell script to run a standalone main() (for Hibernate schema generation) this way
File output example