When you're working with a Java project in Eclipse and you need to add a new jar file to your project, you don't need to close down Eclipse or your current Eclipse project (as I've seen a few people do). In fact, here are all the steps you need to take to add a new jar file to your Eclipse build path:
- Outside of Eclipse, copy the jar file you need to your project's jar file folder (use Windows Explorer, Mac Finder, a terminal, or other). Most projects have a
libfolder for their jar files, so I'll assume that's where we're going to add it.
- In the Eclipse Package Explorer, select your project, and then press the F5 key to refresh your project. (Alternatively you can just select the
libfolder, and refresh it.)
- Now when you look at your
libfolder you'll see your new jar file in there.
- Next, right-click that jar file, then select Build, and then Add To Build Path.
That's all you have to do to add your new jar file to your current Eclipse project build path.
Eclipse build path notes
A few other notes about adding a new jar file to your Eclipse build path:
- If you prefer using the menu system, you can add your jar file to the Eclipse Build Path like this: select Project, then Properties, then Java Build Path, then Libraries, and finally Add Jar.
- To refresh your project view in the Eclipse Package Explorer, you can either press the F5 key, or right-click the project and select the Refresh menu option.
- As mentioned above, it can be faster to just select your
libdirectory and refresh it.
Adding other files to your Eclipse project
As one other note, this same technique works just as well for other files you want to add to your Eclipse project - image files, XML files, whatever. In those cases you don't need to modify your build path, but you follow the same first two steps: Add the file to your folders outside of Eclipse, then press F5 or click Refresh to tell Eclipse to re-scan your project folders.