views:

127

answers:

5

Hi I want to create an exe file for my java app.

I tried with some third party softwares JEXECreator, successfully created the exe file and its working fine in my system, when I tried with another machine, it’s not working. I got the following error

    * The error occurred while running the application. The exit code is 0x10000223.
    * Contact the vendor of the application for troubleshooting.

    java.lang.ClassNotFoundException: com.sample.SampleMain
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at com.ucware.JEXEClassLoader.run(Unknown Source)
         at com.ucware.JEXEClassLoader.main(Unknown Source)
    **************************************

I know there is something wrong with the classpath which I set.

Actually I want to create the exe file myself without using any third party software.

I found the steps in lot of sites

Created the manifest file named Sample.mft with following contents

         Manifest-Version: 1.0
         Main-Class: 
         Class-path:

In this I have some doubts,

  1. How the Main-Class should be added, with the full package name (com.sample.SampleMain) or the class name alone (SampleMain) or with the extension (SampleMain.class)

  2. How the class-path should be added, I have 4 java classes and 2 jars in my project. How to add all these in the class path, and do I need to add the java jdk in classpath.

  3. Where the manifest file should be saved

  4. What should be the manifest file extension (mf or mft)

  5. In command prompt from which directory I should create the exe file (from my project folder or src folder or the folder which contains all the java classes)

  6. What’s the syntax should be used while creating jar in command prompt

(jar cmf Sample.mf Sample.jar Sample1.class Sample2.class Sample3.class Sample4.class jar1.jar jar2.jar) like this or (jar cvfm Sample.jar sample.mf *.class)

When I did something like this I am getting a jar instead of exe file, When I run the jar in command prompt using "java -jar sample.jar" then I am getting class not found exception".

Actually how to create an exe file instead of jar file, that means just by double clicking that exe file, should run my app in any machine.

Can anyone help me to do this?

Thanks in advance.

A: 

Can't speak for JEXECreator, but I can recommend JSmooth (http://jsmooth.sourceforge.net/). I've successfully used it for several projects (e.g. this SWT based Java app).

Matthew Phillips
me too, but it's quite terrible. it's pretty much broken
Xorty
A: 

Well I will recommend you to create one bash file instead of doing complex things and by double clicking on it you can run your application.Yeah but you cant change its icon but there are many free tools are available by using which you can easily convert bash file to exe.

Rupeshit
A: 

Personally, I like JSmooth. That is just wrapping. This means it is still a Java application. When executing the exe, it will unpack the jar to a temporary folder and then execute it with javaw -jar ...

A second option is gcj. But that is absolutely a bad choice. That doesn't wrap the jar in an exe, but it really compiles it to native system code. But this slows down your application very much. You can check some results of my timing on this topic.

Martijn Courteaux
+2  A: 

I use the Ant tool under Eclipse IDE to work with InnoSetup and Launch4J to create the EXE and its installer which it also manages the classpath...

A guide? You can refer to:

http://www.eteks.com/tips/tipCreationExe.html (in French)

eee
A: 

I had some positive experience with Excelsior JET. Unlike gcj it actually works and execution times are faster than that of an executed .jar file. The downside is that it's not for free.

xor_eq