How to compile all .jars to .m2?

I am trying to debug a mvn compilefile with many dependencies using javac.

This is how I try to do this:

CLASSPATH=`find ~/.m2 -name *.jar -print0`; javac -verbose BogusFile.java

My problem is that I'm not sure how to say find to separate each jar found with the unix ( :) file separator .

Maybe -printfhas a solution?

+3
source share
2 answers

Sorry, I can’t answer your question, but give a possible different approach to the solution.

If you need to build a class path for your maven project, you can run the Maven Dependency Plugin copy-dependency target in your project:

mvn dependency:copy-dependencies

Maven ( ) target/dependency, target/dependency/*; ( ).

:

:

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"));
    }
}

:

C:.
├───src
│   └───main
│       └───javaBogus.java
└───target
    └───dependency
            commons-lang-2.6.jar
            log4j-1.2.16.jar

:

.....\bogus>javac -cp target\dependency\*; src\main\java\Bogus.java

:

C:.
├───src
│   └───main
│       └───javaBogus.classBogus.java
└───target
    └───dependency
            commons-lang-2.6.jar
            log4j-1.2.16.jar
+7

Unix , Python, .

export TEST_CLASSPATH=`find ~/.m2 -name *.jar | python -c "import sys; print ':'.join(sys.stdin.read().splitlines())"`
javac -classpath $TEST_CLASSPATH:./ BogusFile.java
+1

All Articles