Reputation: 14918
I have a bunch of jars in a folder and in order to streamline the classpath setup I'm using the new (in Java 6) classpath wildcard syntax:
CLASSPATH=":/$JARS/*"
which will pick up all jars in the $JARS directory. So far so good.
However, there's one jar in that directory that I need to appear first in the classpath and the docs for the wildcard syntax state that the order of the jars is implementation dependent and cannot be relied upon.
What I was thinking of doing was adding the one jar I need to appear first explicitly, in front of the wildcard:
CLASSPATH=":/$JARS/first.jar:/$JARS/*"
Now that would mean that first.jar
would appear twice in the classpath, first the explicit reference and then with the wildcard. Is that going to cause me any problems?
Yes, I know that I could put first.jar
into a different directory to avoid the problem but lets just say that doing that would involve a lot of hassle that I'd rather not have to deal with (I'm dealing with a 3rd party product).
EDIT:
I need the jar to appear first because it contains some XML configuration files (which are loaded as resources) which need to override XML files with the same name in another jar (supplied by the 3rd party vendor). Just to clarify, first.jar
is the only jar under my control. All the other jars in the directory are supplied by the 3rd party vendor.
Upvotes: 1
Views: 2875
Reputation: 5661
Yes, the same jars/classes can appear multiple times on the classpath. The jvm searches them in order.
more info at this question: How does JVM deal with duplicate JARs of different versions
Upvotes: 5
Reputation: 9
There will be some problems . Sometimes the JVM might work fine but other times it might not recognise any of the jars . Its better to have one jar in the classpath .
Upvotes: 0