2 main and jar

Hi,

I have a package of 6 classes, and 2 of them have a main method, a login class and the class called by this login class.

How do I create a .jar file so that , in windows, it runs just by double-click the .jar file?

With only one class with a main method there is no problem, but now ... ?

Thanks for helping a novice ,

[354 byte] By [kiekeboea] at [2007-11-27 6:48:32]
# 1

It not exactly clear what the set up is.

You mention that you have a "login class" and another "called" by it. If you intend that the first class's main() method will always be invoked first, and some method in this class will always invoke the main() method of the other class, then there is no problem - just include the first class in the jar file manifest. The fact that the other class has a public static void main() method is irrelevant.

On the other hand if you intend that both of the main() methods might, on occasion, be invoked first, then you have a problem. Neither the Java executables (java.exe/javaw.exe) nor the OS (in response to a double click) can read the user's mind. Something more than a double click on the jar file is needed.

A possible solution is to launch your application from a .bat file. Different launching files can be provided for the different main methods that you intend be invoked. Windows allows a number of executable script fie types, including some that can respond to files that are dropped on them (eg launching your Java app in different ways depending on the extension of the file.)

pbrockway2a at 2007-7-12 18:21:57 > top of Java-index,Java Essentials,New To Java...
# 2
Indeed, I want to invoke always the login class.How do I point to it?thanks,
kiekeboea at 2007-7-12 18:21:57 > top of Java-index,Java Essentials,New To Java...
# 3

If the class is called Login and is in the myapp package, you would add an Main-Class entry in the jar manifest saying:Main-Class: myapp.LoginThis is explained (with examples etc) in Sun's Tutorial - http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html

The whole section on using jar files (http://java.sun.com/docs/books/tutorial/deployment/jar/index.html) is useful if this stuff is new.

pbrockway2a at 2007-7-12 18:21:57 > top of Java-index,Java Essentials,New To Java...