Add external jar to the project and build process using maven

2.8k views Asked by At

I have a maven multi-module project working. I also have a code (abc.jar-non maven) with some feature's to be integrated into one of the module(say module1) of existing maven project. How would i import abc.jar into my maven project? I tried the following: Created /src/main/lib and copied jar into lib. Configured pom.xml with:

<dependency>
    <groupId>abc</groupId>
    <artifactId>abc</artifactId>
    <version>1.0</version>
    <systemPath>${base.dir}/lib/abc.jar</systemPath>
    <scope>system</scope>
</dependency>

Also tried using <systemPath>${project.basedir}/lib/abc.jar</systemPath> But, it warns 'dependencies.dependency.systemPath' for abc:abc:jar should not point at files within the project directory, unresolvable. I was told, it could be achieved using assembly. But i could not achieve. Please help. I'm using maven 2.4v

4

There are 4 answers

0
zforgo On

Use ${basedir} or ${project.basedir} expression instead of ${base.dir} variable. All expression is case-sensitive.

You can try it by maven-help-plugin's evaluate goal.

mvn help:evaluate

1
Twinkle On

Follow this below link you will find the solution,

http://softwarecave.org/2014/06/14/adding-external-jars-into-maven-project/

0
Qingwei Xu On

SystemPath is working fine to me, and try to use ${baseDir} instead of ${base.dir}, or change maven version to 3.0

0
srikanth On

Thanks. I have tried using assembly plugin to do the task. And it worked.

<assembly>
    <id>bin</id>
    <formats>
        <format>tar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>

    <files>
        <file>
            <source>src/main/lib/abc.jar</source>
            <outputDirectory>lib</outputDirectory> 
        </file>
    </files>
</assembly>