Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an exe file in java

Tags:

java

file

exe

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.

like image 280
SWDeveloper Avatar asked Jun 25 '10 06:06

SWDeveloper


2 Answers

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)

like image 173
eee Avatar answered Oct 04 '22 21:10

eee


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).

like image 44
Matthew Phillips Avatar answered Oct 04 '22 20:10

Matthew Phillips