954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do I create a JAR library?

Hey

I want to create a JAR library but not sure how to in MyEclipse. Im currently doing it manually using jar command but I cant seem to get it correctly

The library code is:

public class LibAdd
{
	public static int addtwonumbers (int a,int b)
	{
		return a+b;
	}
	
}


From this, I generate the .JAR (using what command in case Im doing it wrong). Named (for example) LibAdd.jar

Then in another project, in the build path, I include the LibAdd.jar and I want to do this:

public class AnotherClass
{
   public static void main(String[] args) 
     {
		LibAdd l=new LibAdd(); //Can I do this,having no main???
                  int x=l.addtwonumbers(2,3);
                  System.println.out(x);
               //OR
                  System.println.out(l.addtwonumbers(8,5);


	}
}

Thanks for the help :)

riahc3
Posting Pro
545 posts since May 2008
Reputation Points: 50
Solved Threads: 2
 

Eclipse official documentation Creating a New JAR File

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Hey

I want to create a JAR library but not sure how to in MyEclipse. Im currently doing it manually using jar command but I cant seem to get it correctly

The library code is:

public class LibAdd
{
	public static int addtwonumbers (int a,int b)
	{
		return a+b;
	}
	
}

From this, I generate the .JAR (using what command in case Im doing it wrong). Named (for example) LibAdd.jar

Then in another project, in the build path, I include the LibAdd.jar and I want to do this:

public class AnotherClass
{
   public static void main(String[] args) 
     {
		LibAdd l=new LibAdd(); //Can I do this,having no main???
                  int x=l.addtwonumbers(2,3);
                  System.println.out(x);
               //OR
                  System.println.out(l.addtwonumbers(8,5);


	}
}

Thanks for the help :)


hmm maybe this could help: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-33.htm . lol sorry peter_budo. haha we used the same thing :)

DavidKroukamp
Practically a Master Poster
Team Colleague
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
 

Perfect.

Worked perfectly. Thanks. I imagine this is what I need.

riahc3
Posting Pro
545 posts since May 2008
Reputation Points: 50
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You