Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

Java, Eclipse , and JARs

I want to create a JAVA program that is a JAR.  I know I can Export using Eclipse.  I understand the concept of a JAR.  However, do I need a main function in my program?  If not, then how do I run and test within Eclipse ?

 Will any public method be visible to the calling program?
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

You do need a main() method, and a manifest file that tells the jar which class holds it.
Avatar of HLRosenberger

ASKER

What do you mean which class hold it?  Can I just have one class ?
You can run an app contained in a jar - as you probably realise. The jar should contain a manifest file (text file), in which certain things can be stated, the most important of which is which class, in the jar, is the class which contains the main method. Then, when the jar is double-clicked or called from the command line, the JVM knows where to look. You can have one class, if that's all your app requires, or many, but the one with the main main method will be the one that starts the app ball rolling.
And, how do I call functions within the jar?
I was going to add to my comment that this :

"Main-Class: pc"

is the complete contents of a manifest file of mine for example, for a class called pc. So my pc class's main method will be what the jar opens to start the app.

Calling functions "within the jar" isn't exactly the right idea - you call functions in classes and between classes in the same way whether the files are in or out of the jar. Just use the same principles that you already use in Java - the jar file is just a condensed convenience for holding them all in one place : jar = Java archive file.
ok, now how do I make the  JAR known to my other app, which is a Android app?
I will only be calling the function within the JAR from another JAVA app, an ANdroid App.
Just include your jar in the build path while compiling and in the runtime path while running .
In your Android app's class , you will have to import the class from your jar  first , and then invoke the function you need
ASKER CERTIFIED SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks
Thx too.
(Check my out-of-time comment in your other question too). ;)