Eclipse - How to add/remove external JAR into Java Project's Classpath

There are multiple ways you can add an external JAR into the classpath of a Java project in Eclipse, but all goes via adding them into build path. Many beginner's struggles to add JARs into classpath and we will try to address that problem in this tutorial. You will learn step by step tutorial to add an internal or third party JAR in your application's CLASSPATH in Eclipse Indigo. Since this feature has hardly changed in any Eclipse version, you can follow same steps in Eclipse Kepler, Indigo, and Juno version to add JARs into classpath. Since Eclipse is the most popular Java IDE and used by many companies, it's important for a Java developer to know Eclipse in and out. It will not only help to work better but also to create the better impression among your teammates.

Btw, if you are new to this blog, then don't forget to check out my earlier Eclipse articles e.g. 30 useful Eclipse shortcuts for Java developer (see here) and 10 tips to debug Java program in Eclipse (see here), very useful to increase your productivity in Eclipse.

If you are super excited to master Eclipse IDE, you can even check out books like Eclipse in Action for more comprehensive study on Eclipse's features and tricks.



Steps to add external JARs into Eclipse Project's classpath

Here is the step by step guide to add external JAR files into a Java project's classpath into Eclipse IDE:


1) Right-click on your Java project and Select Properties, as shown below :

How to add external JAR into Classpath in Eclipse


3) Choose Java Build Path and Select Third tab, Libraries

How to remove a JAR into Eclipse's classpath



6) Alternatively, Click Add External JAR to add JAR from any folder on your machine. It will open file chooser to choose the JAR file from the file system and add that into CLASSPATH.

How to add external JAR into Eclipse's Java project classpath

Once you click Open, the JAR will be shown in your project's build path as shown below :




8) Once you add JAR, you can see them in same Library window. You can remove them by selecting and clicking Remove button.



5) Click Add JAR to add JAR from any other project in same Eclipse workspace. It will open a selection window to choose the JAR file from existing Eclipse project and add that into your application's classpath.


7) If automatic build is not set then make sure you refresh your project and build it again.

That's all about how to add/remove JAR files into your project's classpath in Eclipse. If you are using Maven with Eclipse e.g. via M2Eclipse plugin then you don't need to do this exercise, as Maven dependencies are always in the build path. You just need to add the new library to the pom.xml and Maven will download and add into Maven dependency automatically.

Other Eclipse tutorials and tips for Java Programmers
  • How to attach source code for JAR file in Eclipse? (guide)
  • Eclipse short to print System.out.println statements? (shortcut)
  • How to remove debug Java program in Eclipse? (guide)
  • How to increase console buffer size in Eclipse? (steps)
  • How to fix Maven repository search not working in Eclipse? (solution)
  • How to use spaces instead of tabs in Eclipse? (guide)


No comments :

Post a Comment