Search
Calendar
October 2017
S M T W T F S
« Sep    
1234567
891011121314
15161718192021
22232425262728
293031  
Your widget title
Archives

PostHeaderIcon Maven: How to use jars in a lib/ folder?

Case

I have to work on an “old-school” project: without Maven (and even without integration within Eclipse). The JARs depended on by the application are located in a lib/ folder. Besides, I cannot add JARs to company repository.
How to integrate Maven with this lib/ folder?

Solution

First of all, you have to enable the support of Maven within IntelliJ IDEA: select the project > right click > add framework support > select Maven.

Create a pom.xml and complete the main information.
Identify the JARs which are relatively common (eg those available in http://repo1.maven.org/maven2/), and add them as dependencies.

Now, you still have to deal with “uncommon” JARs

Quick and (very) dirty

The quickest way is to add the JARs as dependencies, declared with scope system, eg:

<dependency>
    <groupId>unknownGroupId</groupId>
    <artifactId>someArtifactId</artifactId>
    <version>someVersion</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/foo.jar</systemPath>
</dependency>

The main drawback of this dirty solution is that when you generate your archive, the JARs depended on with scope system will not be exported… Quiet a limitation, isn’t it?

(A bit) Slower and (far) cleaner

You have to declare a “remote repository”, of which URL is local, such as:

<repository>
    <id>pseudoRemoteRepo</id>
    <releases>
        <enabled>true</enabled>
        <checksumPolicy>ignore</checksumPolicy>
    </releases>
    <url>file://${project.basedir}/lib</url>
</repository>

Then, declare the dependencies like:

<dependency>
    <groupId>UNKNOWN</groupId>
    <artifactId>foo</artifactId>
    <version>UNKNOWN</version>
</dependency>

Move and/or rename the JARs, for instance from lib/foo.jar folder to the actual one, such as lib/UNKNOWN/foo/foo-UNKNOWN.jar.

Now it should be OK ;-).
In my case I prefered to add Maven Assembly plugin with the goal jar-with-dependencies, to be sure to build a unique JAR with complete exploded dependencies.

Leave a Reply