abo sager Posted August 13, 2005 Share Posted August 13, 2005 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 More sharing options...
egrath Posted August 13, 2005 Share Posted August 13, 2005 Hi,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.Example: 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: testnow create the jar file:jar cvfm hello.jar manifest hello.classand execute your jar file with:java -jar hello.jarIf 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.Egon Link to comment Share on other sites More sharing options...
hmaster10 Posted March 26, 2006 Share Posted March 26, 2006 (edited) 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: testmain-class: test<enter> Edited March 26, 2006 by hmaster10 Link to comment Share on other sites More sharing options...
LLXX Posted March 26, 2006 Share Posted March 26, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now