Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This may be a stupid question, but....

Status
Not open for further replies.

pipk

Programmer
Feb 20, 2001
455
0
0
GB
Is there a correct way of turning and java class file into an executable that can be run without the use of the "java" command in a shell??

i.e. such as the way you execute an application in windows with a double click etc??

do you have to write a program in another language, such as c/c++, that calls the java application? I am fairly ignorant in these areas having only ever run java from a shell command line interface.

cheers in advance.

pipk
 
No, you can do that with what they call JAR files. A Jar file is a Java Archive file. Kind of like a Zip file with all your classes and files within it. There is a Jar utility that comes with the JDK to create them.

If you create a JAR file and a manifest file for it, then you can do this. The manifest file contains information about what class to run etc. kind of like the main method. Look out on the web site and search for JAR files.

I believe that is what you want to do. I have used them with applets, but not as executables. I did read something that allows them to act as executables though.

Post your findings, if you get it to work.
Brian
 
You'll have to add a manifest to your .jar. BZJavaInst is right - a .jar is a .zip, just with another extension. And there's a special directory in the root of the .jar, called "META-INF", that contains the file Manifest.mf. This file is plain text and looks as follows:

Manifest-Version: 1.0
Main-Class: your.package.YourClass

You can use the following command in a shell to create the .jar (assuming you're in the top directory of your output directory and have created the META-INF directory there):

jar cvf META-INF your/package/*.class your/other/package/*.class [...]

Be sure to add all the packages your application uses.

Another option is to create a batch file that calls "java your.package.YourClass" and then create a shortcut to it. This way you can even use your own icon. But I suggest using the .jar functionality.

Hope this helps...
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
You can also change your class files to executable files. Take a look at this link:-


Keep in mind your java program will not be able to implement in other OS beside windows after changing the format of the file.

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Many thanks guys, I shall be exploring this further in the next month or so...

pipk :)
 
Also, if you're able to pick up a copy of Microsoft J++, you can compile your code into a windows executable. However the JAR approach works as long as there is a Java Runtime Environment (JRE) on the machine you want to run it on. If there isn't, then you need something like J++. I haven't looked into Excelsior, but I imagine that it does something similar to J++. (I'm not sure of the release date of Microsoft J# for .NET, but I'd guess that you can get a compiled executable from there much like in J++.) Liam Morley
lmorley@gdc.wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
It just occurred to me that you might have posted this so that you have an easier way of executing your own code as opposed to making it easier to distribute. If that's the case, all you have to do is create a batch file. Create a new text file, give it a .bat extension, and include whatever you'd type at a command line inside the file. This is probably by far the easiest approach to having an executable java program, but not recommended for distributing. Liam Morley
lmorley@gdc.wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
Hi!

I just wanted to warn you about using Microsoft J++. In fact it will work quite fine to compile your java code to an .exe file that doesn't even need a Virtual Machine (JRE). But this will completely corrupt your code without any warning.
For example if your are using swing or AWT classes they will be exchanged with classes from the microsoft packages. This will also happen when you compile .class files for different platforms. So the code won't work on them.
So, even if it looks (and is) quite easy to build GUI's and .exe files with J++ (or Visual J) better do not use it. You will have lots of trouble afterwards. Believe me.

Greetings, Kai.
 
holy cow.

i posted this thing a whole year ago, and people are still replying to it??????!!!!!

amazing.
 
Hi,
There's a standard development kit from microsoft that can trun java class files into windows exe file. Here's the link to download the SDK


There's another software JEXEPACK at that can trun class files into exe but it actually works as a batch file i.e. it passes the same command line arguments as you do to execute the class file.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top