Tuesday, June 26, 2012

Adding JAR Files to your Project in Eclipse



Hello fellow Java Developers..,
In this post I'll show you how to add JAR files to your project in ECLIPSE IDE.

  

Eclipse ide provide 2 ways to add JAR files to our project:

  1. Adding External JARs
  2. Adding JARs
(yes there is a difference in those 2 options)

Adding External Jars:

In this option Eclipse add JAR files to Project by Absolute path..,
i.e., If you add a jar file which is located on desktop your system,to your Eclipse Project
then the path would be : c:/documents and settings/admin/desktop/xxxxxxx.jar.
The main Disadvantages of adding jar files like this are:
  • If you move or delete the jar file located in absolute path then project won't work.
  • If you move your project to other PC then you need to place the jar file in same location as in the previous system OR you need to add the jar file to project again.

Here is how you can add JAR file using "Add External JAR s" method.
  1. Rigth Click on your Eclipse Project.
  2. Go to Build Path
  3. Select "Add External Jar Archives" , if this option is not listed go to STEP 4 or go to  STEP 6
  4. Select "Configure Build Path"
  5. Select "Add External JARs" under "Libraries"
  6. You'll get a File dialog : Select the JAR file you want to add and OK.

See the following Video:

video


Adding JARs

 In this option  Eclipse will add the JARs from Relative path in Project Directory.
All you have to do is copy the jars to your Project folder.
Now even if you move your project to another PC you don't need to worry about the JARs

Lets see how we can add Jars to our Eclipse Projects Permanently using this method:

  1. Copy all the JAR files you need to include in your project.
  2. Now Create a new Folder in your Eclipse Project as Follows
    1. Right Click and select New
    2. Select "Folder" option
    3. Provide name for folder ( say: APIs)
  3. Now paste all the jars inside that folder.
  4. Now Right click on project select "Build Path"
  5. Select "Configure Build Path"
    Select "Add JARs" [ NOT Add External JARs ] option under "Libraries" Tab
  6. A file Explorer will open up. Notice that it shows only files on you Eclipse workspace.
  7. Now select the JAR files that you psated in your project folder.
Observer that the path for Referenced jar is Relative [ Example /<Project Name>/APIs(folderName)/ ]

See the Following Video

video

If you have any further queries contact me or post a reply.
Hope you find, what you're looking for.







No comments:

Post a Comment