tags:

views:

24

answers:

1

Hi,

I've used Maven to build my command line application. Now I'm going to distribute it as a jar file, and I need to handle the app's dependencies.

I don't want to include all dependencies in the jar file as described here.

The environment where my app will be run has Maven. I'd like Maven to run my jar looking at file META-INF/groupId/artifactId/pom.xml inside the package so it knows what the dependencies are and can find them in the repository.

Any ideas ?

+1  A: 

Include a main class in the jar that 1) extracts the pom to a temporary file, and 2) launches a new maven process using this file with the -f parameter and the goals dependency:resolve and dependency:build-classpath

like this:

mvn -f /temp/tempfile.xml dependency:resolve dependency:build-classpath -DoutputFile=/temp/classpath.txt

then 3) reads the newly created classpath file and 4) launches a new java process using the new classpath file

java -cp yourjar.jar;<created classpath>

Your pom.xml will have to include all required repository information, of course

seanizer
+1 for creativity
Pascal Thivent