Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reference classes and methods in JAR file inside Eclipse?

Tags:

java

eclipse

Basically I wish to use the methods of a class within the Jar file, which looks like this:

IDE Screenshot

Can somebody please tell me what I need to import in order to use those methods and variables?

like image 387
Banned Avatar asked Mar 12 '12 01:03

Banned


1 Answers

You don't need to import anything.

Jar files aren't imported, they are added to the classpath.
From the screenshot you've posted, we can see that the myJar.jar file is included in your eclipse classpath, so there's nothing more to do there.

Classes are imported, if they are in a different package.
Your Examplew class is in the default package. BMIcalculator is also in the default package. Because they are the same package, you don't need to import it.

You should be able to simply make references to BMIcalculator from within Examplew. Just try it.

Try compiling this code - it should work:

public class Examplew
{
    private BMIcalculator calc = new BMIcalculator();
}

You might get warnings about the unused private field, but you can ignore that for now.

If that doesn't work for you, then please post the error, because it doesn't look like the problem is with your imports (or your classpath)

like image 70
Tim Avatar answered Oct 19 '22 23:10

Tim