Link to home
Start Free TrialLog in
Avatar of sunshine737
sunshine737

asked on

how to make an .exe of my java application

Hello,

I have finished my application, and now it has to be deployed on different systems, so i want to make an .exe of my application and give an icon to it, so when the user double clicks it, the application will start.
I have read some docus on the internet, but its little confusing, some are saying to make jar files and some are giving some tools.
can somebody explain me in steps how to do this and also why we need to do such way and also the best way of doing it.

what i want to achieve is that make my application like any other software that i can have it on a cd and i can just install it on other systems.

thanks.
Avatar of Mick Barry
Mick Barry
Flag of Australia image



You could also deploy it using JavaWebStart: http://java.sun.com/products/javawebstart/

Of course you need to have a server available in order to use that. But if you have it, its the best way for deploying applications. User just clicks the link on your web page, and the application will install/run.

btw:
1. User needs to have java installed.
2. Creating native exe from java is not a good option.

Avatar of ashok3sep
ashok3sep

You have to create a Jar file of all the class files of your application and then you have to create a manifest file and then add to your Jar file and then later you need to have Java Runtime environment installed in the computer where you need to check and thats alll

you are finished !!!!

http://www.captain.at/programming/java/executable-java-application.php


the link above is helpful for creating the Jar file and Manifest file and so on........

Regards,

Freedom.


And if you want to see JWS in action, here are some nice  demos:

http://www.jgoodies.com/downloads/index.html
SOLUTION
Avatar of ashok3sep
ashok3sep

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunshine737

ASKER

what is the difference between jar files and .exe and what about .run that we see in some software installations, how can i have the same kind of installment procedure
A jar file is collection of class files and requires a jre to run.
an exe is a native executable.
objects,

have you seen many java aplications turned to native executables? I really would like to know, cause I dont think that it is usefull. I mean: why develop application in Java, just to make exe out of it?
well i tried making an .jar using eclipse but on double clicking its doing nothing
For some cases it is not possible to have a JRE in the computer where you need to check or RUN your application.

So Java Provides a option to create as an .exe so that everybody get use of it.

not to the people who know Java.

Regards,
Freedom


Dont make it using eclipse, make it by hand, so that you will know what it is that you are doing.

Use the links provided by objects.
You have to specify the main class for the manifest file

did you do that
you have to navigate after specifying the class file for the jar Archive and the place for storing the Jar archive
Dont click FINISH Button after you select the class files and the place to store your *.jar file.

proceed with the NEXT Button and then you have to select import with compile time warnings TextBox

and then click next to go the page of Manifest.

here you have to select the Generate manifest and then the place for storing the Manifest.

then you have to give the name of the Main class  by selecting .Main class is the class containing (( public Static void main(String[] args)) .

Then click FINISH BUtton

you are Done !!!!!!!!!!!

Then double Click it and you see Bingo!!!!!!!!!!!!!!!!


Regards,

Freedom.
yes i gave the manifest still nothing is happening.........

but i think what i want it can only be done by making an .exe
What you get when you Double click on the Jar file

Can u please post the Error
It could be Helpful to analyse
Study the linke below for Error analysis

http://www.captain.at/programming/java/executable-java-application.php

NOTE:-
If your Using Swing components in your application and if you use a Older JRE then you have to upgrade it to a newer version for compatability.


You can also start you application from the CommandPrompt ( DOS )

after  you make your jar File you can run it using:

java -jar YourFileNameForJAR.jar
from file im going to export and then selecting jar file and then its showing the .java files to the right, im selecting one and checking the options down - export generated class files and resources and selecting the export destination to desktop and also checking the option compress the contents of the jar files and then next
cheking the other options export class files with compile errors and warning and next
choosing the option generate manifest file, seal option and main class and then there is only finish button enabled, so im clicking finish and its generating .jar file successfully but when im double clicking nothing is happening
>>I mean: why develop application in Java, just to make exe out of it?

Because not having one can be thoroughly inconvenient in terms of dependencies

Incidentally, for a 'true' executable (all others i know use an encapsulated [or not] vm) you can use gcj, but it only supports unwindowed apps and lower jdk (think 1.1)
> you can use gcj

That has already been mentioned in an earlier link.

Check the Manifest file by editing it in the Eclipse Environment to check for the correct Main class name
u can use picozip to create a jar file from all ur class files then use it with exe4j from www.exe4j.com to create the executable its very easy to use just follow the steps
make jar file then , make a .bat file with the launch command of ur .jar file.

read the successfull answer already posted here,

https://www.experts-exchange.com/questions/21198328/create-a-exe-for-java-application.html

or
if u want only .exe file, then use JBuilder to make deployment, it will also provide to make .exe files for windows as well as to make deployments for other o/s .
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hello edwardiii,

iam able to make the jar file and its working fine, but how can i give an icon???
Thanks for accepting

:-)

I dont know how to give an Icon for a Jar file.

But you can give a icon for your application...


Image img;
            URL myurl = getClass().getResource("Images/remote-application.GIF");
            Toolkit tk = getToolkit();
            img = tk.getImage(myurl);
            setIconImage(img);
This you can see when you have the

"strg + Tab pressed"

Regards,
Freedom.
oops i have a problem again, i tried with an small prog and it worked and now i tried with my real application, it is give me an error "could not find main- program will exit"- when im doubli clikcing the jar file......i dont understand why, im following the same steps
are you using eclipse for ur Jar creation or else........

Java2exe.exe

this is a trial version which can convert your java class files to windows executable......

or you can use native compilers like GCJ ( I dont know How ) to convert Java bytecodes to maschine codes.....

if it works with small program then it should work also with your real application.......

are you using any swing components in your application ......

then you have  to upgrade your JRE.....
yes im using swing components, how can i upgrade it
what version of JRE are you using right now

im using eclipse to make this jre, how to see this version???????
You will see the version of JRE in the Package Explorer in the Eclipse


or just type java -version in the command prompt

U:\>java -version
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
thats OK ...

then it should work.......
try it out again

do you get any error messages when creating a jar

before the jar creation your application works properly.....
i
Howdy, vihar123.

Glad to hear from you again:)  Here's what I can suggest:

1)     Regarding making an icon for your Jar, I can only recommend (if you're using Win2k or equivalent) that you right-click your JAR, select "Send To" and "Desktop(create shortcut)".  Go to your Desktop, right-click your new shortcut-to-your-JAR icon, select Properties, go to the Shortcut tab, and click the "Change Icon" button.  Browse to whatever icon you'd like.

2)     These IDEs are finicky:)  As a recent Visual Basic programmer, I see why all the Java experts are masters at working with Java at the command line.  I'm not sure why your current attempt to JAR using NetBeans 4.0 is failing, but it may help if you take the 5 steps I listed in my original post and then share with us (verbatim) the literal names you entered or items you chose for each step, along with the name(s) and location(s) and package(s) of any class(es) you were attempting to JAR.
well im using all these jar files in my program and my main prg also calls an other class......i mean my main prg is gui.java and it also calls an other class treeselectionobject.java.......and when im creating the jar file using the above steps, its giving me a popup saying cannot find main class, program will exit...........

oraclexsql.jar
classes111.jar
classes111.zip
classes111_g.jar
classes111_g.zip
classes12.jar
classes12.zip
classes12_g.jar
classes12_g.zip
classes12dms.jar
classes12dms_g.jar
classgen.jar
connectjdbc.jar
dms2Server.jar
dnsns.jar
jce.jar
jdev-rt.zip
jsse.jar
ldapsec.jar
localedata.jar
nls_charset11.jar
nls_charset11.zip
nls_charset12.jar
nls_charset12.zip
ocrs12.jar
ocrs12.zip
ojdbc14.jar
ojdbc14_g.jar
charsets.jar
plugin.jar
rt.jar
samples.jar
servlet.jar
soap.jar
sunjce_provider.jar
sunrsasign.jar
transx.zip
xdb.jar
xmlcomp.jar
xmlcomp2.jar
xmlmesg.jar
xmlparserv2.jar
xschema.jar
xsqlserializers.jar
xsu111.jar
xsu111_816.jar
xsu111_817.jar
xsu12_816.jar
xsu12_817.jar
I see.  You've got enough jars to open a general store:)  Well, there are three things I can think of that can help us determine why you're getting a "cannot find the main class" error:

1)     From the command line, can you go the directory this non-working .jar is in and type "java -jar nameOfYourJar.jar".  What do you get?  Also, with "java -version" what do you get?

2)     If you're running Win2k, open an explorer window (it doesn't matter what directory you're in), click Tools, Folder Options, click the File Types tab, type "j", and locate the line item for Jar - Executable Jar file. Click the Advanced button, then click edit.  Post the full path you see here.  

3)     In terms of your jaring of the main class (we'll ignore your plethora of other .jars listed in your last comment for now), please take the 5 steps I listed in my original post and then share with us (verbatim) the literal names you entered or items you chose for each step, along with the name(s) and location(s) and package(s) of the main class you were attempting to JAR.
im getting this when im giving it on the command prompt


U:\>java -jar gui8.jar
Exception in thread "main" java.util.zip.ZipException: Das
ebene Datei nicht finden
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:112)
        at java.util.jar.JarFile.<init>(JarFile.java:127)
        at java.util.jar.JarFile.<init>(JarFile.java:65)
Okay.

Next, what is the package your gui8 class is in?  Share the selections you made for each of the five steps below:

1)In the Eclipse Navigator window, select the .java file you wish to jar (for me, "TemplateCal.java"). [EXAMPLE: guis.gui8]

2)  Right-click the .java file and click "Export". Ensure "JAR file" is selected and press "Next". [EXAMPLE: Done as listed]

3)  Two important steps here.  In the top-left "Select the resources to export" window, make sure the package your .java file resides in is selected. [EXAMPLE: Did this]  If you are unsure, verify by going back to the Navigator window.  Next, in the "JAR file" drop-down, make sure the name of the Jar to be created matches the name of your .java file (e.g. TemplateCal.jar for TemplateCal.java). [Example, name of the JAR to be created is "gui8", name of the .java file is "gui8.java"] Click Next, leave the default settings in the "JAR Packaging Options" window, and click Next again.

4)  If you use the "Generate the manifest file" setting, all that remains is to go to the bottom of the "JAR Manifest Specification" window (the section is "Select the class of the application entry point"), click the "Browse" button next to the "Main class" textbox, make sure the name of your file is highlighted (in my case "TemplateCal"), and click "OK".  If you see multiple file names in the "Select Main Class" window, click the one your application begins with, then click "OK". [EXAMPLE: List name of file you selected]

5)  Click "Finish", go to your desktop, and the executable JAR should run.  What I noticed is that Eclipse defaulted to another class I had in the package, so you have to visually ensure what you're intending to JAR is what Eclipse is JARing.  The 5 steps listed above will ensure this:)
You get this error because
>>U:\>java -jar gui8.jar
>>Exception in thread "main" java.util.zip.ZipException: Das
>>ebene Datei nicht finden
 >>   at java.util.zip.ZipFile.open(Native Method)
 >>       at java.util.zip.ZipFile.<init>(ZipFile.java:112)
 >>     at java.util.jar.JarFile.<init>(JarFile.java:127)
 >>       at java.util.jar.JarFile.<init>(JarFile.java:65)

some of your Jar might be dependent on some other Jar...

so you have to set the classpath in the manifest file for solving the problem......


regards,

Freedom......
i followed exactly the 5 steps as u have stated but still getting this problem

>>>so you have to set the classpath in the manifest file for solving the problem......

how to set this path????
Hi, vihar123.

I apologize, am totally swamped at work, and don't have the time to experiment with Eclipse to see whats going wrong for you.  Please open a fresh question so all EE members will see it and can offer assistance.  Your question should be something like "How does one add numerous JARs to a JAR file with Eclipse version x.x".  Apparently something more is required than the process we got to work for you in JARing a simple JAR that had no component JARs.