Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes generate an executeable file with java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "generate an executeable file with java" Watch "generate an executeable file with java" New topic

generate an executeable file with java

Trung Tran

Joined: Jun 28, 2002
Posts: 13
do anybody know if it is possible to generate an executeable file with java? and how?

I hear and I forget;<br />I see and I remember;<br />I do and I understand.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Why is this in Swing/JFC/AWT?

I'm moving it to a more appropriate forum... Java in General: Intermediate.

And to answer your question:

Yes... and No. There is no built-in way to generate an executable file in Java. One of Java's main points is "Write Once, Run Anywhere" and it accomplishes this through compilation of source down to bytecode, and then running the bytecode on a machine specific interpreter. In more recent versions of this interpreter the bytecode is actually compiled to machine code before it is run. This is the behavior of the HotSpot JVM, the default JVM since Java 1.2.

However, there have been several schemes to produce "compiled" Java programs, and these basically fall into 3 camps:
  • Translaters - All these compilers do is translate the Java source code into C or C++ code and compile it. I know GNU was working on a Java compiler like this, and I think there were a few others...
  • Packagers - All these compilers do is package your class files together with a small JVM. Visual J++ (bleh!) did it this way, and I think a few others may have, too...
  • Others - There are other compilers that it isn't clear exactly what they do to compile Java code. These are usually targeted at large scale development, and look to be a bit out of the price range of a single developer... JOVE is an example of this.

  • The big question is, "Why?" Why do you want to natively compile Java code? Speed? No need for a JVM? Obfuscation of code? No matter what the reason, there is always a tradeoff and you'll be sacrificing a lot of the points of using Java by natively compiling.

    Write once, run anywhere, because there's nowhere to hide! - /. A.C.
    Cindy Glass
    "The Hood"

    Joined: Sep 29, 2000
    Posts: 8521
    If you are simply trying to get something that you can click and execute - then use a jar file or a .bat / .sh file to invoke your application.
    If you are trying to hide your code, try using an obfuscator.
    If you are trying to make it easier to install, get a tool like InstallSheild which will package everything up in a single downloadable executable, but after it is installed it unpacks and is NOT an executable.
    If you are trying to make it work on only one platform, there are some tools out there that will actually compile java for you. This should be WAAAAAAY a last resort choice.

    "JavaRanch, where the deer and the Certified play" - David O'Meara
    Trung Tran

    Joined: Jun 28, 2002
    Posts: 13
    sorry for my really bad english!
    i didnt mean generating a class file to an executeable file or something, i know there are ways to do that, but that is not the point why java was developed i think. like Nathan said, write one, run anywhere that is why java is that powerfull for many software development.
    well, what i mean is if it is possible to write a java application that create an executeable file. hope this is better to understand.
    regards, trung
    Cindy Glass
    "The Hood"

    Joined: Sep 29, 2000
    Posts: 8521
    You want to WRITE a COMPILER? Using Java as the tool language? What language would the input file be in?
    Or perhaps you just want to invoke the java compiler in your java program??
    This topic discusses that.
    Trung Tran

    Joined: Jun 28, 2002
    Posts: 13
    thanks for the informations.
    yes, that was what i wanted to say, writing an compiler with java. but i dont think that this is possible?!
    regards, trung
    ravindran shanmugam

    Joined: Aug 30, 2001
    Posts: 15
    Try JavaCC, it is a compiler compiler tool ( JavaCC - Java Compiler Compiler )
    it is close lex and yacc.
    - Ravindran
    Abhinav Anand
    Ranch Hand

    Joined: May 02, 2002
    Posts: 113
    Hi guys,
    I mugged my head a lot on this java class to exe issue. I have had some recent development in this area.
    Try this link:
    Download the personal edition of Exelsior Jet which will get you started in this area. It is a great tool to begin with and it is absolutely free. However to make the exe run on another computer you will need another utility named JetPack, which you gotta download from the link given below:
    Try this link also:
    Although the jexepack is not free but it is worth a try to try it.
    I agree. Here's the link:
    subject: generate an executeable file with java
    Similar Threads
    How to make jar file executeable ?
    convert a jar file to exec.
    Auto generate wsdd file
    jar executeable
    asking about compilers