hi,guys i'm on the track of packaging my stuff, but i have a question for the executable jar file 'runme.jar', I need to start the programs as java -jar runme.jar server; java -jar runme.jar client; java -jar runme.jar ;
but i have a main() class for client, and another main()class for the server can I make two excutable jar files "client.jar" , "server.jar". and make them under the "runme.jar"
but when i do that, i can not use the form "java -jar runme.jar [mode]"
anyone can help me to resolve this? thanks
Oliver Weikopf
Ranch Hand
Joined: Feb 17, 2004
Posts: 58
posted
0
No, you may not include a jar for each version or deviate from the given syntax. The instructions are very clear there.
Use one main only. If you find no appropriate class to put it into, you might want to add a class called Startup or something and give it nothin but a main method that calls the main() appropriate for the arguments.
Zhaozhe Ruan
Greenhorn
Joined: Mar 06, 2006
Posts: 17
posted
0
can i call a main() from another main()?
Thirumurugan Mylrajan
Ranch Hand
Joined: Jan 26, 2006
Posts: 64
posted
0
Originally posted by Zhaozhe Ruan: can i call a main() from another main()?
What Oliver means is that its good to have only one entry point as per the requirements given by Sun. If there is only one entry point creating the manifest file for the JAR is easy.
Create a dummy class with main() which will instantiate the client or server objects according to the paramaters passed. Dont have static main methods on these classes. Use Constructor overloading to pass appropriate paramaters.
Hope this is clear.
SCJP , SCJD. (IBM 142 in progress).
Jeroen T Wenting
Ranch Hand
Joined: Apr 21, 2006
Posts: 1847
posted
0
no, that's not what he meant. public static void main(String[] args) is just another static method which you can call like any other static method. So your launcher can call Client.main(args) or Server.main(args) from its own main method without instantiating anything.