How do I get Maven to include a jar in my Eclipse Referenced Libraries?

10,705

Solution 1

In your pom.xml add a <dependencies> tag and add all the Jars dependencies in that. It will be downloaded at the time of build.

like this

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-a</artifactId>
      <version>2.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-b</artifactId>
      <version>1.0</version>
      <type>jar</type>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
     ....
</project>

see more here http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

For publicly available Jars you can search the dependencies here http://mvnrepository.com/

For the Jars that are not publically available you can install locally, by

 mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

see here

I am not sure how to install third party jars from inside the Eclipse. There must be some way using m2eclipse plugin.

Solution 2

You can also import the jar into your maven repo using m2e if you're on eclipse indigo. Go to file/import/maven/install or deploy an artifact to a maven repository

You will need just to fill up the group and artifact id

Share:
10,705
eph_tagh
Author by

eph_tagh

Updated on June 27, 2022

Comments

  • eph_tagh
    eph_tagh almost 2 years

    I am attempting to take an existing Eclipse project and add a pom.xml so that I can use Maven for automated builds. In the project I have a jar file in the Referenced Libraries that is not in the Maven repository. What do I need to do in order to get Maven to recognize the jar file?

    I have sort of fumbled around with the element without any success.

    Windows XP, Eclipse 3.6.1, Maven 3.0.2

  • eph_tagh
    eph_tagh about 13 years
    Thank you very much. I was missing how to install the jar locally. Everything worked for me as soon as I installed it locally and updated my pom.xml to match what was installed.