In Maven, how output the classpath being used?

Alexander Bird picture Alexander Bird · May 20, 2013 · Viewed 46.1k times · Source

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.

Answer

Janik Zikovsky picture Janik Zikovsky · Dec 12, 2014

To get the classpath all by itself in a file, you can:

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

Or add this to the POM.XML:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.9</version>
        <executions>
          <execution>
            <id>build-classpath</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>build-classpath</goal>
            </goals>
            <configuration>
              <!-- configure the plugin here -->
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

From: http://maven.apache.org/plugins/maven-dependency-plugin/usage.html