views:

320

answers:

7

Without learning new programing languages, can we using Java get .exe (executable windows file) software directly? And is there away to make .jar (Java ARchive) software transform to.exe (executable windows file)?

Would this conversion effect the performance of the software?

+3  A: 

You can launch a .exe from java with Runtime.exec() or ProcessBuilder.

You can make a .exe launcher with http://launch4j.sourceforge.net/

Maurice Perry
A: 

I was using a wrapper for java to make exe files for a pretty long time:

JStart32 It is just a wrapper for *.jar files.

But ask yourself: Wouldn't an exe kill the purpose of javas platform independency?

Acron
Well, you could ship / provide more then one download: an .exe, a .dmg, a .rpm, etc.
Tim Büthe
+3  A: 

Yes, it is possible: http://www.excelsior-usa.com/articles/java-to-exe.html

Sorin Comanescu
Very informative article, Thanks "Sorin Comanescu"
MAK
You're welcome!
Sorin Comanescu
A: 

Check out jsmooth (free) and exe4j and you might want to read make your swing app go native

Tim Büthe
+5  A: 

One of the important points of Java is that it'll run on any platform (e.g. Windows, Linux, etc) that has a suitable Java Virtual Machine (JVM) installed. A .exe file is compiled to work on only one platform.

What you think you want is to turn a .jar into an .exe so you can launch it easily. What I expect you really want is just an easy way of launching a Java app that anybody can understand, including your parents.

The easiest way of doing this is to create a Windows batch file that launches your Java app. One of line of script, one new file, one new instruction to your users - "Double click on runme.bat"

There are ways of turning a .jar into an .exe, but you should think about whether that's really what you want, and if so, why.

Note: you can launch a .jar in Windows by just double clicking on it, as long as the main class is specified in the manifest. You might want to look into tools like Apache Ant to simplify building .jars and their manifests. Just a thought.

EDIT:

A batch file in Windows is a simple text file that contains commands. You can test the commands by running them in the command prompt (Start -> Run -> cmd). When you run a batch file the commands in it are just fed to the command prompt one at a time.

How to run a Jar from the command prompt: "java -jar myfile.jar"

If you create a batch file (.bat - use Notepad or your favourite text editor) containing "java -jar myfile.jar" (without the quotes!) then double-clicking it will launch the main class specified in the manifest of myfile.jar. myfile.jar has to be in the same folder as the batch file, though.

If you use the command "java -jar lib\myfile.jar" (again, without the quotes) then your batch file will run myfile.jar, which needs to be in a folder called lib that's in the same folder as the batch file. Use this approach when you have a whole load of Jars with your application and you don't want to shove them in the user's face :)

Note that moving the batch file will break it, unless it uses absolute paths to the jar file - e.g. "java -jar C:\dev\myfile.jar". Of course, if you use absolute paths then moving the Jar will break the batch file anyway :)

Also, note that you should be able to run a Jar file just by doubling clicking on it in Windows, as long as the main class is specified in the manifest. Give it a try. Of course, convincing your users that they can double click on it is another matter entirely...

As a final note, if you use a batch file, your users will get a nice command prompt window sitting in the background until your Java app closes. That is, unless you start your batch file command with "start". E.g. "start java -jar myfile.jar". If you have your app configured to log to System.out or System.err, you will still get a command prompt when your app writes to either of those streams, though.

Final final note, in the Linux world the equivalent of batch files are shell scripts.

Cosmic Flame
I like the idea of you knowing what I want more than myself :) Would you be able to give me more instructions on the windows batch files? (Detailed if possible) Thanks.
MAK
I wanted the exact same thing when I was at Uni :) I had written something neat and wanted something I could show my parents - none of this .jar nonsense! Looking at your other questions made me think that you are in a similar place. I'll edit my post to include some instructions about batch files if you give me a minute :)
Cosmic Flame
Awesome :) all this is new to me. You are very helpful!
MAK
I'm glad I could help :) Are you a student at University or learning in your own time or what?
Cosmic Flame
Makes sense. Well, as you no doubt know, the best way to improve your programming skills is to program! :) Good luck!
Cosmic Flame
+1  A: 

I'm not sure if this is an appropriate answer because I don't work with Java but could you not using a shortcut file pointing to the java runtime and pass the jar as an argument, this

I realise this is not the only way, nor probably the best way but to me it seams a little better than creating a batch or converting to an exe file if all you're looking for is a convienient way to launch a java app

Crippledsmurf
+1  A: 

The very simplest way is to write a windows batch (.bat) file which will start the application.

Umesh Aawte