File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes making a .java file .exe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "making a .java file .exe" Watch "making a .java file .exe" New topic

making a .java file .exe

Alan Watts

Joined: May 14, 2001
Posts: 28

Hi there,
I am sure this is a simple (or silly) question. I have just written a GUI as a java application. It works fine if I launch it from the command prompt in Windows. Is there a way of converting the .java file to a Windows executable (.exe) file? ie. so that a user can double click on a Windows .exe file icon to launch the java app?
Muchos Gracias
Alan Watts
Gautam Sathe

Joined: May 24, 2001
Posts: 18
I don't think we can make an .exe from a .java file. But you can do one thing, write a batch file with instruction to run the java byte code (i.e. java MyClass).
Hope this helps,

Ender Everett

Joined: Mar 31, 2001
Posts: 19
As far as I know, there are three things you can do...
1 - Have the installer (if you use an installer) create a shortcut on the desktop or in the start menu somewhere that executes the same thing your command-line instruction would be. It looks the exact same, and you don't have to mess with really compiling the code into an *.exe. Java was never intended to fully compiled, as far as I know...which is the whole point of cross-platform portability. Use a shortcut, that's why they're ther
2 - You could write a *.bat file and either put that up on the desktop (with a better icon, I'd hope) or write a *.bat file and then make a shortcut on the desktop or start menu to that *.bat file. For progs that need a more complicated startup command, then I think this is the way to go...
3 - You could go find the *.java/*.class to *.exe compiler. It is out there somewhere, but it's 100% not made by once you make your program into an *.exe, you're out of the loop, so to speak. It can never be transferred to a Linux or Sun system accept through X Windows...and that sucks. The compiler is an open-source project, and if you're REALLY looking to make the prog into an executable, then this is the only way I know of. There is absolutely NO reason to do this, however, unless you are doing it strictly to improve execution time (which is does by eliminating the JVM overhead). From what your situation sounds like, this isn't the way to go.
I am absolutely not an authority on Java or Windows... so if some local guru wants to tell me I'm wrong, go right ahead! I have messed with the *.bat files and the shortcuts porsonally, and they work just fine. The shortcut-to-*.bat is exactly the method that the jEdit editor works, by the way...
Take a look at the project and see what you think about their startup method... no *.exe here. Just *.bats and an optional shortcut. That way everything stays inside of *.jar files or *.class files and Linux, Sun, Windows, etc people can all play with it.

Don't sweat the petty stuff, just pet the sweaty stuff.
Kirill NKaufmann
Ranch Hand

Joined: May 25, 2001
Posts: 46
Hi Alan, yes, its possible to make an exe. Just go here:
download the trial version and read the help file to find out how to use the utility. Seems to work pretty well for me.
Alan Watts

Joined: May 14, 2001
Posts: 28

Many thanks to all the respondents for their quality advice.
Hopefully, in time when I am wiser and greyer I can contribute usefully here as well.
Alan Watts
Ben Brown

Joined: Jun 04, 2001
Posts: 4

You could make an exe file but if you want this to run on many platforms creating an exe will not do you any good.
You can create a windows shortcut and set the target:
c:\JDK1.3\bin\java.exe TestFile
*you might have to specify TestFile.class
and set the start in dir to where TestFile is located.
I hope that works for you.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Wiser! Did you hear that guys? Wiser, I kinda LIKE that.
But enough with that GREYER stuff. Really, that is no way for a gentleman to talk. .
I, of course, am MUCH to young to have to worry about things like grey (snicker).
Sure glad that I wasn't who you were refering to .
[This message has been edited by Cindy Glass (edited June 07, 2001).]

"JavaRanch, where the deer and the Certified play" - David O'Meara
Alan Watts

Joined: May 14, 2001
Posts: 28

Just call me Daddy...
Kirill NKaufmann
Ranch Hand

Joined: May 25, 2001
Posts: 46
Kirill NKaufmann
Ranch Hand

Joined: May 25, 2001
Posts: 46
and anyway if you make an exe using JET u will have to include a bunch of large JET dll's in order to run your exe elsewhere so it kinda defeats its own purpose, still worth a try though.
Brian Coates
Ranch Hand

Joined: Jul 03, 2001
Posts: 42
This probably isn't the route you're looking for, but MS Visual J++ and Symantec VisualCafe will allow you to compile a project into an exe.
I agree. Here's the link:
subject: making a .java file .exe
Similar Threads
Networking between a Java application and an executable launched with Runtime.exec()
How to convert java file to .exe file.
Java to EXE
Get File Version
Launching a DOS batch file