Question:
Help to make the following JAVA code into an exe file.?
anonymous
1970-01-01 00:00:00 UTC
Help to make the following JAVA code into an exe file.?
Five answers:
Nigel
2010-08-29 08:52:40 UTC
It is possible - if you really want to, have a look at http://gcc.gnu.org/java/ for one implementation of it.

But also read http://www.excelsior-usa.com/articles/java-to-exe.html as there are quite a few reasons for and against doing what your asking - plus some alternatives.
Dude Guy
2010-08-29 10:21:49 UTC
Create an executable jar:

http://csdl.ics.hawaii.edu/~johnson/613f99/modules/04/jar-files.html

Or google and find some other tutorial. Your IDE might have an option for creating an executable jar, in other case it's just one command that you have to write or copy paste to the command line.



On most modern systems all you have to do to run an executable jar is to double click it. How to set a custom icon on the application I don't know, but it seems this thread mentions web start:

http://forums.sun.com/thread.jspa?threadID=5435922
deonejuan
2010-08-29 09:56:08 UTC
Java bundles the byte code with read-only resources into a .jar.



On the Windows desktop, double-click of a .jar icon runs the java program. To pack a .jar file correctly does take some knowledge. IDE editors such as NetBeans, Eclipse will pack the .jar and both of those use ANT -- a java-based script engine to batch the .jar making.



Otherwise, most commonly, you write a C program to launch your program. You can include just the JRE in your archive, which as I write this, is still royalty free.



Looking your code over, I see you are not quite ready for distributed solutions.
Light Cloud
2010-08-29 09:16:08 UTC
As others have mentioned, java is incapable of creating executable files (.exe). The java compiler (javac) takes your source code (.java) and compiles it into bytecode (.class), and the Java Virtual Machine then runs your bytecode -- this is how Java programs are run. One consequence of this is that you cannot run Java code on a computer that doesn't have Java installed (i.e. the computer must have the Java Runtime Environment [JRE] installed to run java programs).



Basically, the only way to get around this is to get an Ahead of Time compiler; however, IMO, there really isn't a good, free compiler like that at the moment.





If you're ok with requiring the JRE to be installed, you can compile java programs with:

javac *.java



And then you can run the program via:

java program

(where program.java is where your main method is)



Note that although you do need the JRE, you do not actually need the IDE though. You can run java programs directly from the command prompt, or you can tell Windows to associate JAR files with the java virtual machine, etc...
AnalProgrammer
2010-08-29 01:04:00 UTC
Java does not create exe files.

Your IDE will compile you program and create a class file that can be executed using the java command.

There should be an option in your IDE to create a distributable build. This will create a jar file that will contain the correct manifest information and allow you to run the jar file by double clicking.



You need to learn more about your IDE.



Have fun.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...