1

I have dependencies in my pom.xml like this:

<dependency>3.jar</dependency> <dependency>1.jar</dependency> <dependency>4.jar</dependency> <dependency>2.jar</dependency> 

I have a maven project that when deployed, will have a directory structure like this:

myproj/ |_lib/ |_1.jar |_2.jar |_3.jar |_4.jar |_start.sh 

The start.sh loads all the jars in the lib folder like this:

CLASSPATH=./lib/* 

Problem is, when I echo the CLASSPATH, it loads the jars alphabetically:

CLASSPATH=/lib/1.jar;/lib/2.jar;/lib/3.jar;/lib/4.jar; 

I want it to be what maven uses:

CLASSPATH=/lib/3.jar;/lib/1.jar;/lib/4.jar;/lib/2.jar; 

I can do

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

but it prints out the jars in my local repository:

CLASSPATH=C:\.m2\repository\com\project\3.jar;\.m2\repository\com\project\1.jar;... 

I think I can modify the generated output but I am looking for a better solution.

Any ideas?

Thanks!

2
  • "it loads the jars alphabetically" - why is that a problem? Unless you have the same class in different JAR files (which you shouldn't) the order of the jar files in the classpath is not important Commented Sep 20, 2017 at 10:59
  • Actually that was the problem - same class in different jars. And since the jars are proprietary, I have no other choice but to order the classpath. Commented Sep 20, 2017 at 11:52

1 Answer 1

1

You can use the prefix parameter to dependency:build. From the docs:

prefix

The prefix to prepend on each dependent artifact. If undefined, the paths refer to the actual files store in the local repository (the stripVersion parameter does nothing then).

User property is: mdep.prefix.

For example:

mvn dependency:build-classpath -Dmdep.outputFile=cp.txt -Dmdep.prefix=/lib 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.