Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Maven, how output the classpath being used?

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.

like image 331
Alexander Bird Avatar asked May 20 '13 17:05

Alexander Bird


People also ask

How do I find my classpath in Maven?

The exec plugin provides another way to display the Maven generated classpath: $ mvn exec:exec -Dexec. executable=echo -Dexec. args="%classpath" [INFO] Scanning for projects...

Does Maven add dependencies to classpath?

Maven does set the classpath to the dependencies correctly, but not prefixed with repository location. It will look like this in your Manifest file. It is upto you to place the dependant jars in the same folder as the jar which you are running.

What does the given command do Mvn dependency build classpath?

Description: This goal outputs a classpath string of dependencies from the local repository to a file or log.


1 Answers

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

like image 75
Janik Zikovsky Avatar answered Oct 02 '22 16:10

Janik Zikovsky