File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing a JAR file from within a program

 
Steve Greenfield
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47271
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47271
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . 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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47271
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47271
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More about jar files (for Java 5) here.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic