Jump to content

Java code to an executable?

Recommended Posts

How can I convert a java code to an executable file? I mean to a .jar file.

For example, an assembly code can be converted to .exe by the order MASM and then LINK.

I know how to compile the code in the DOS by JAVAC and then executing using the order JAVA .

But how can i make it an executable file without the need of the code? Is there a way that it can be a .EXE file?

Link to comment
Share on other sites


when you compile your java sourcecode you get a bunch of .class files which contain the executable code interpreted by the java interpreter. In order to stuff these .class files together to a jar file (java archive) you have to use the tool "jar.exe" which is installed with the SDK.

You also need a so called "manifest" file which describes in which class File inside the jar archive the main method exists.


suppose you have a simple "hello, world!" program which consist of the following code:

class hello
       public static void main( String[] args )
               System.out.println( "Hello, World!" );

when you now compile this program using "javac hello.java" you get the file "hello.class" which you can execute by typing "java hello".

To create a Jar Archive first create a file called "manifest" which contains the following content:

Main-Class: test

now create the jar file:

jar cvfm hello.jar manifest hello.class

and execute your jar file with:

java -jar hello.jar

If you want to create a .exe File you have to write a wrapper in a native language like c or c++. See one of my posts in this Forum below.


Link to comment
Share on other sites

  • 7 months later...

i get a "Failed to load Main-Class manifest attribute from file.jar"

should the manifest file be save without an extension?

edit: Found the error. there should be a new line after the main-class: test

main-class: test

Edited by hmaster10
Link to comment
Share on other sites

Java is a semi-compiled interpreted language, so it must be run under the Java VM. I guess you could use a wrapper around the bytecode like .NET does, but the Java VM itself is rather huge...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...