File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "generate an executeable file with java" Watch "generate an executeable file with java" New topic
Author

generate an executeable file with java

Trung Tran
Greenhorn

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


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

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.


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

    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
    Greenhorn

    Joined: Jun 28, 2002
    Posts: 13
    thanks,
    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"
    Sheriff

    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
    Greenhorn

    Joined: Jun 28, 2002
    Posts: 13
    hi,
    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
    Greenhorn

    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:
    http://www.excelsior-usa.com/jet.html
    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:
    http://www.excelsior-usa.com/jetdl25jpu.html
    Try this link also:
    http://www.duckware.com/jexepack/index.html
    Although the jexepack is not free but it is worth a try to try it.
    Thanks,
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: generate an executeable file with java
     
    Similar Threads
    jar executeable
    Auto generate wsdd file
    convert a jar file to exec.
    asking about compilers
    How to make jar file executeable ?