How to Include External Jar on My Netbeans Project

How can I include external jar on my Netbeans project

If you copy your jars into the source code directory, they will be in your final jar. Nevetheless, I am not sure if this will work 100% of the time.

There is a great post at java-forum that states the following:

Except for a select few circumstances, what works best for me is to
simply merge the files manually. A .jar is basically a .zip with
organized contents, and you can open them in almost any .zip capable
archive program (I just use gnome's standard archiver, File Roller,
and it works great). Backup your jar file and open it in the archiver
of your choice, and do the same for each library jar in the library
directory. Drag and drop the working folders (IE, everything EXCEPT
the META-INF Directory) from each library into your jar's root path
(alongside your META-INF and your app's root package). Now drag the
META-INF/MANIFEST.MF file from your jar to your Desktop or any other
folder. Open it, and erase the Class-Path and X-COMMENT lines. Don't
forget to leave a blank newline at the end of the file! Save the new
manifest file and drag it back to your jar's META-INF directory,
overwriting the old one. Test the jar.

How to include external libraries when moving my NetBeans project?

I found the solution:

  1. Create a folder named lib or whatever name inside your NetBeans project folder.
  2. Place the .jar file inside that folder.
  3. Add the .jar file to your project from NetBeans.
  4. Now the your project is portable with the external library .jar
    file.

Adding external JAR to Maven project in NetBeans

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.

How to add external libraries in NetBeans IDE?

Quick solution in NetBeans 6.8.

In the Projects window right-click on the name of the project that lacks library -> Properties -> The Project Properties window opens. In Categories tree select "Libraries" node -> On the right side of the Project Properties window press button "Add JAR/Folder" -> Select jars you need.

How to include jars in lib into project jar file in Netbeans?

OK, found the answer at the following site : http://arunasujith.blogspot.com/2011/08/how-to-build-fat-jar-using-netbeans.html

Including external jars permanently in NetBeans

But when i open the same project in my friends NetBeans, it doesn't
recognizes this library. I've to manually select the file placed
inside the projects dist/lib folder. How to avoid this?

You can't avoid this because it's not a problem actually. To compile and run a project you need to have access to the external libraries involved in the development, so if you open your NetBeans project in a different computer than yours you will definitely need to resolve the reference to the external libraries. There's no way for the IDE to do it automatically as far as I know.

Can't i give the relative path to the lib folder for that specific
library somewhere in project properties?

You could just give it a try. IMHO if the real goal is to share a project with other developers then I'd change the strategy. I'd create a Library (Tools -> Libraries) and tell my mates to create the very same library including the JCalendar JAR files in the library's classpath. I'd include this library in the project properties and finally I'd use a versioning tool like Git or SVN to share the project.

By doing this your mates still need a copy of the JAR file wrapped in a NetBeans Library, but the project properties won't point to a fixed/relative path looking for a JAR file but wil include a reference to a given Library. The Library itself will resolve the dependency to the JAR file. If you take a look to the project.properties file you'll see something like this:

javac.classpath=\
${file.reference.jcalendar-1.4.jar}

But if you as I've suggested then you'll see something like this:

javac.classpath=\
${libs.JCalendar.classpath}

Here libs.JCalendar.classpath will resolve the dependency so your mates can have the actual JAR file located in whatever folder they like and the project should compile just fine.

Another option is using Maven to manage the projects dependencies but honestly I'm not a Maven expert so I can't help you in this path.

using external jar dependency in netbeans

Ok so I found the solution to add the library as a dependency. I created a new java library project on netbeans (instead of building the jar on the command line and externally adding it to the project with mvn install) then I added the sources files there and then built the project to create the jar files. I then modified my pom.xml to an updated version of the project and finally went to the dependencies right click on the the jar and clicked on manually install artifact and found the jar on my netbeans workbench. After that I just had to refresh my project and the errors were gone.



Related Topics



Leave a reply



Submit