SSV
SSV

Reputation: 860

Adding external JAR to Maven project in NetBeans

When I right click on my Maven project and choose the Add dependency option and I type my external jar's name in query, it is not found. How to add external jar to a Maven project?

Upvotes: 40

Views: 88351

Answers (5)

Giovanni Perea
Giovanni Perea

Reputation: 348

one trick is in the netbeans main menu select: profile->options->java->maven put in the global execution options the parameters example: -Dfile=C:\Users\anonym\Desktop\commons-pool-1.6.jar -DgroupId=commons-pool -DartifactId=commons-pool -Dversion=1.6 -Dpackaging=jar

where de parameter -Dfile is the location of the jar file -Dfile=routeToJar

after that select your project. then rigth clic on the select project. and then select Run Maven->Goal. when the wizard appear type in as Goals install:install-file .. and then clic OK buttom

Upvotes: 0

Ojonugwa Jude Ochalifu
Ojonugwa Jude Ochalifu

Reputation: 27257

This answer is for jars that are in the maven repo

Let's say I want to add log4j-1.2.17.jar to my project, all I have to do is find it in maven repository

enter image description here

Step 2 is to copy that and place it inside the dependencies tag of your pom.xml` file:

<dependencies>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.4</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
     ....
     ....
  <dependencies>

Step 3 Build and clean your project. The jar file will be in your dependencies folder afterwards

enter image description here

Upvotes: 5

Paul
Paul

Reputation: 7325

From the NetBeans forum:

  1. Open the Projects tab.
  2. Right-click on Dependencies.
  3. Select Add dependency.
  4. Set groupId to: group.id (can be anything)
  5. Set artifactId to: artifact.id (can be anything)
  6. Set version to: 1.0 (can be anything)
  7. Click Add to continue.

Dependency is added to pom.xml and appears under the Libraries node of Maven project. Continue:

  1. Expand Dependencies.
  2. Right-click on library (e.g., group.id).
  3. Select Manually install artifact.
  4. Set Artifact to install with the Java Archive (.jar) file path.
  5. Click Install locally.

Library is installed locally with dependency attributes (coordinates) entered in steps 4 - 6.


I found those instructions helpful when going through the NetBeans GUI. Basically when right clicking to add a dependency, the group id, version, and name must be populated with anything. Then that "dependency" will be listed in the dependency drop down. Right click on that newly created dependency and right click to install locally and navigate to the appropriate jar file.

Upvotes: 116

mkleint
mkleint

Reputation: 2321

In Netbeans, the approach to adding dependencies that are not in repository is reversed. First come up with maven coordinates in the Add Dependency dialog. Then right click on the new dependency node and trigger "Manually install Artifact" action.

Upvotes: 7

user8658912
user8658912

Reputation: 1592

You can follow this tutorial: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Example:

Install the jar to your local maven repository:

mvn install:install-file -Dfile=cxf-2.7.3.jar -DgroupId=org.apache.cxf -DartifactId=cxf-bundle -Dversion=2.7.3 -Dpackaging=jar

Edit the pom.xml file in your project to include the newly added dependency:

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.7.3</version>
</dependency>

This should work regardless of the IDE you are using.

Upvotes: 24

Related Questions