Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Adding jar dependency in pom.xml

I have never built my java applications by maven. But when i am trying to do that it's giving me error. I have created JAR file from other java application just by exporting as JAR from that application. Now i want to add this JAR in my maven application. I don't really how to do that.

this is how i have added in pom.xml. But i don't really know what should be it's artifact id. Seriously what is artifact id?

<dependency>
        <groupId>ProjectZen</groupId>
        <artifactId>community</artifactId>
        <scope>system</scope>
        <version>1</version>
        <systemPath>${basedir}\libs\ProjectZen.jar</systemPath>
    </dependency>

I am getting below error

Missing artifact ProjectZen:community:jar:1

Thanks Fahad Mullaji

like image 740
Fahad Mullaji Avatar asked Nov 19 '14 05:11

Fahad Mullaji


People also ask

How do I add dependencies to POM xml?

Open the pom. xml file. under the project tag add <dependencies> as another tag, and google for the Maven dependencies.

Where do I put dependencies in POM?

The dependency is added to the consuming project's pom. xml file. Right-click pom. xml file of the consuming project, and select Run As>Maven Build.


1 Answers

If it is custom jar you need to do following things Open cmd and type following command

  mvn install:install-file  -Dfile=path-to-your-artifact-jar \
                      -DgroupId=ProjectZen
                      -DartifactId=community
                      -Dversion=1
                      -Dpackaging=jar
                      -DgeneratePom=true

Now, the “ProjectZen” jar is copied to your Maven local repository.

In pom.xml

  <dependency>
    <groupId>ProjectZen</groupId>
    <artifactId>community</artifactId>
    <scope>system</scope>
    <version>1</version>
    <systemPath>${basedir}\libs\ProjectZen.jar</systemPath>
</dependency>

now the “ProjectZen” jar is able to retrieve from your Maven local repository.

like image 179
sar Avatar answered Sep 24 '22 17:09

sar