Search code examples
javaeclipsejarreferencebuildpath

Cannot import Jar in Eclipse


I am having trouble using external Jar files in my java project. I know this question is common here, but I already checked the others and they did not work for my. I have a solution called "testjarreference", in that solution I have two projects:

testproject
projecttojar

I then added a package to "projecttojar" named "testPackage" and a class "referenceme", with a method "test()" that simply outputs to the console. I then exported this project as a jar, and in testproject went to Configure Build Path > Add External Jars... where I then selected the exported jar.

In the class in testproject where I have the main method in it, I tried to do "import projecttojar.testPackage.referenceme;" but it keeps saying "The import projecttojar cannot be resolved" no matter how I change it. I even tried creating a 'lib' folder and placing it in there, no luck.

I also tried closing out of eclipse, and cleaning the project, no luck. This is frustrating because everywhere I have read the solution is always the same; make sure the jar is added to the build path, which it is, so I have no idea why it is not working. Any help?


Solution

  • Press “Ctrl + Shift + O“ and eclipse will do the import automatically. http://www.mkyong.com/eclipse/how-to-import-class-automatically-in-eclipse/

    If it doesn't work, must be a problem of importing the jar to the project.