| Author |
Executing a JAR file from within a program
|
Steve Greenfield
Greenhorn
Joined: May 07, 2007
Posts: 2
|
|
Hey everyone- I'm trying to write a user interface for a game engine that I downloaded as an executable JAR. The readme file simply suggests executing the engine.exe file from your program. Once this is done you send commands + receive responses as plain text. Can anybody tell me a standard idiom for executing this jar file + communicating with it in plain text? Once I have this I know how to fill in the commands + process the responses. I'd be grateful for your help. Thanks.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Welcome to the Ranch. If you are running Windows, try double-clicking the .jar's icon; that may start it off if it has a proper manifest and a main method.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
. . . Or if you are running the whole thing in Java, unzip the jar, find its manifest, and find what it calls Mainclass. You can try calling Mainclass.main(); in your programming. If it hasn't got a Main class, there ought to be instructions with it or a readme file to tell you what to do.
|
 |
Steve Greenfield
Greenhorn
Joined: May 07, 2007
Posts: 2
|
|
|
The readme.txt file is of limited help. It merely says to use the engine.exe file from within your program. Once it's running you can send commands + receive its responses in plain text. I have the jar in the same directory as my java files. I just need some suggested code idioms to start up the .exe file + communicate with it.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Is there any javadoc to go with the games? You will need that to show you whether you need any command-line arguments for the main method. Try unzipping the jar file. A .jar file has exactly the same format as a .zip file, with a manifest file added. See if you can find the manifest file, and read that. More details about jars in the Java Tutorial, here, and here. This page is about manifests, and this bit tells you how to find a class with a main method (let's call it "EntryClass", in package "com.games.mygame"). When you have got the jar file in your classpath, you should be able to call the main method with
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
More about jar files (for Java 5) here.
|
 |
 |
|
|
subject: Executing a JAR file from within a program
|
|
|