7

I am new to Eclipse IDE, I created a new project named "Hello World", and I need some APIs which are contained in a jar file.

I created a folder called "lib" under the project folder "Hello World" (parallel with src folder), and I import the .jar file into this lib folder, it extracts all the things to this lib folder automatically.

Then I created my HelloWorld.java class under src folder, however, when I put import ro.xxx.xxx.xxx, eclipse complains "the import ro cannot be resolved". Actually, the ro is under the lib folder.

I am stuck here. Shall I make this lib folder under the src folder instead of parallel with it? Please kindly give me some suggestions, thanks in advance!

Kevin
  • 6,711
  • 16
  • 60
  • 107
  • 4
    I think you probably don't want to extract the JAR. Just copy the unextracted JAR file to the lib folder. Right click on the JAR in eclipse and select Build Path -> Add to Build Path. This is a shortcut to going through the project properties screen. – Mike Clark Dec 10 '10 at 16:30
  • @Mike thanks, it works. May I ask how to do the contrary, that is, to package the compiled class into a jar? – Kevin Dec 10 '10 at 16:48
  • 1
    Hi Robert. Have a look at [Java: export to an .jar file in eclipse](http://stackoverflow.com/questions/423938/java-export-to-an-jar-file-in-eclipse) and see if it answers your question. – Mike Clark Dec 10 '10 at 16:57

4 Answers4

17

Project -> properties -> Java build path -> libraries -> add external jars

Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132
  • 3
    But if you are exporting the project or it is shared on a repository, it is better to put them in lib, and instead of add external jars, use add jars and reference it to the lib folder. This way all dependencies will remain intact in the main project when exported. – Johnydep Mar 06 '12 at 11:54
  • 1
    @Johnydep, I believe using maven is even better approach. Here the easiest way was discussed. – Stan Kurilin Mar 14 '12 at 13:21
4

Just Putting jar in lib folder won't work , you need those jars in your class path.

Here it is described how to add jars in to your build path in eclipse

jmj
  • 237,923
  • 42
  • 401
  • 438
2

Add the library to your build path.

Right mouse button on your project --> Build Path --> Configure Build Path...

Libraries --> Add jar

Mark Baijens
  • 13,028
  • 11
  • 47
  • 73
0

After you first create the lib folder parallel to the src folder you need to go back into Eclipse and Refresh the project so that Eclipse finds the new folder and jars. You can either highlight the project and hit F5, or use the right click menu off the project. After that the lib folder and jar files appear and you can right click a jar to add to the build path. If you add new jars subsequently you need to refresh again for Eclipse to find them.

Squidious
  • 21
  • 4