Reputation: 711
I am a newbie in Java.
I have a java file A which I want to call in another java program B.
I want to create jar for the A and use it in B by creating the objects and calling the methods for A.
What type of jar is to be created and how can I add it to the library. Please help how to do it in Eclipse.
Also, how to import the jar in B.
Upvotes: 0
Views: 49
Reputation: 789
Now you can use object of A in B.
import com.A;
public class B{
public static void main(String[] args){
A a=new A();
//.......
}
}
Upvotes: 1
Reputation: 317
You can go to File->Export->jar-File name your jar-file (you do not need a runnable jar)
after that you can open your other project B right-click -> properties-> java build path
select libraries and click on add external jars
choose your exported jar-file. Click ok and it is imported to your actual project B
now you can use classes and methods of this jar-File
Upvotes: 3