• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generate an executeable file with java

 
Trung Tran
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
do anybody know if it is possible to generate an executeable file with java? and how?
thanks
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    Cindy Glass
    "The Hood"
    Sheriff
    Posts: 8521
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Trung Tran
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 8521
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 15
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Try JavaCC, it is a compiler compiler tool ( JavaCC - Java Compiler Compiler )
    it is close lex and yacc.
    - Ravindran
     
    Abhinav Anand
    Ranch Hand
    Posts: 113
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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,
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic