I'm trying debug mvn compile
of a file with many dependencies with javac
.
This is how I'm trying to do this:
CLASSPATH=`find ~/.m2 -name *.jar -print0`; javac -verbose BogusFile.java
My problem is that I'm not sure how to tell find to separate each jar found with the unix file separator (:
).
Maybe the -printf
has the solution?
Sorry I can not answer your question but give a possible other solution approach.
If you need to build a classpath for your maven project you can run the copy-dependencies goal of the Maven Dependency Plugin on your project:
mvn dependency:copy-dependencies
Maven will copy all dependencies for your project (also transitive) to the target/dependency
directory and classpath can be set to target/dependency/*;
(you still have to include your artifact jar).
Example:
Code:
import org.apache.commons.lang.WordUtils;
import org.apache.log4j.Logger;
public class Bogus {
private static final Logger LOG = Logger.getLogger(Bogus.class);
public static void main(final String[] args) {
LOG.debug(WordUtils.capitalize("hello world"));
}
}
Directory:
C:.
│
├───src
│ └───main
│ └───java
│ Bogus.java
│
└───target
└───dependency
commons-lang-2.6.jar
log4j-1.2.16.jar
Compile Command:
.....\bogus>javac -cp target\dependency\*; src\main\java\Bogus.java
Result:
C:.
│
├───src
│ └───main
│ └───java
│ Bogus.class
│ Bogus.java
│
└───target
└───dependency
commons-lang-2.6.jar
log4j-1.2.16.jar
Join all the jars by :
separator, to use as the classpath for the compiler.
export TEST_CLASSPATH=$(find ~/.m2 -name *.jar | sed -z 's/\n/:/g')
javac -classpath $TEST_CLASSPATH:./ BogusFile.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With