This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes How to avoid using systemPath and make maven read jars from /lib Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to avoid using systemPath and make maven read jars from /lib" Watch "How to avoid using systemPath and make maven read jars from /lib" New topic
Author

How to avoid using systemPath and make maven read jars from /lib

Eric Lopez-Fernandez
Greenhorn

Joined: Oct 13, 2011
Posts: 17
Hello,

I am just getting familiar with maven and the project that I'm working on requires me to leave a jar inside of the lib folder. I have accomplished that maven "reads" it when compiling, however, I understand I'm not doing it in the best way. Here is the portion of my POM that does that:

<dependency>
<groupId>org.XLogger</groupId>
<artifactId>XLogger</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/java/lib/XLogger.jar</systemPath>
</dependency>

When I run mvn compile I get the following message:

'dependencies.dependency.systemPath' for org.XLogger:XLogger:jar should not point at files within the project directory, ${project.basedir}/java/lib/XLogger.jar will be unresolvable by dependent projects @ line 84, column 16

Does anybody know a better way to make maven read some jars inside of the lib folder without using systemPath?

Any help will be greatly appreciated!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15662
    
  15

Not only does systemPath not like having the jars inside of the Maven project subtree, it doesn't like relative paths or (IIRC) variable substitutions in the path root - only plain vanilla absolute filesystem paths.

This can be annoying, but Maven does have its reasons.

You will be far better off not fighting them. Install the JAR to a Maven repository and make a normal dependency of it.


Customer surveys are for companies who didn't pay proper attention to begin with.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

Why does the project require you to leave the JAR in the lib folder? What would happened if it was not there? Saying that the resulting code will not run because of a missing class exception is not a valid reason, by the way - there is a huge difference between dealing with the classpath for a build, which Maven handles automatically, and for packaging/runtime.

Last year, when I migrated a number of projects to use Maven (also migrated the sources form CVS to Subversion), the first thing I did was to get rid of the lib directory. No one has missed it.


JBoss In Action
Gopi Chella
Ranch Hand

Joined: Apr 26, 2010
Posts: 53
Instead of placing the jar file in the system path you can check out that particular Xlogger maven context from SVN or CVS and do clean install(skip tests) on your local, by doing this you will get the XLogger.jar in your local repository.


SCJP 1.5
Eric Lopez-Fernandez
Greenhorn

Joined: Oct 13, 2011
Posts: 17
Thank you all very much for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to avoid using systemPath and make maven read jars from /lib
 
Similar Threads
Java Security Exception
Unable to create one single jar file in maven with dependencies included inside
Richfaces + Spring + Maven Setup help
Filtering problem using maven-read-properties plugin in pom.xml file
java.util.MissingResourceException: Can't find bundle for base name in JSF Spring Maven project