Aslan986
Aslan986

Reputation: 10324

Import jar in a project

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

Answers (2)

jalynn2
jalynn2

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

DntFrgtDSemiCln
DntFrgtDSemiCln

Reputation: 1289

Add an import statement in your java class and then use the class. Eg: import com.mypackage.MyClass;

Upvotes: 2

Related Questions