Reputation: 10324
I did this very simple java file:
public class LibTest {
public int mySum(int a, int b){
return a + b;
}
}
Then I exported it as a jar file (using Eclipse wizard).
Then I would like to import this jar in a different Java project and use the method mySum
.
I imported that jar as a Referenced Library
, but I don't know how to invoke the method from my code.
How can I do?
Upvotes: 0
Views: 100
Reputation: 6457
First import the class:
import mypackage.LibTest;
Then instantiate it and call the method:
public static void main(String[] args) {
LibTest libTest = new LibTest();
System.out.println(libTest.mySum(1,1));
}
Upvotes: 3
Reputation: 1289
Add an import statement in your java class and then use the class. Eg: import com.mypackage.MyClass;
Upvotes: 2