Link to home
Start Free TrialLog in
Avatar of Samooramad
Samooramad

asked on

java executable

hi experts,
please I need  detailed steps for this..I don't know what I'm doing..
I have an application and I want to run it on another computer (windows OS)and make it an .exe file so you just double click and it works..please don't give me links to look at unless they envolve exactly what Im asking for because Ive browsed over 20 web sites without understanding what I need to do. Im using JBuilder..
some sites say I need to make a jar file which I did but Im not sure is correct or not..
other sites say I need an installer and I also need to download runtime environment(which I couldn't find anyway) and include it on the CD I will create for users without it on their PCs.. Im lost with no idea what to do


speady answers would be greatly appreciated..thanks for the help

bye
Avatar of sudhakar_koundinya
sudhakar_koundinya

creating a executable jar is better option

A new and cool feature of Java2 is the ability to create executable jar files. A jar file is simply a file containing a collection of java files (typically, java .class files, but any other kind of file could be included as well). To make a jar file executable, you need to specify where the "main" Class is in the jar file, so the "java" command knows what main() method to invoke to get the software going. The procedure is quite simple, and this document provides step-by-step instructions. For more details on jar files, consult http://java.sun.com/docs/books/tutorial/jar/.

   1. First, make sure you have installed Java 1.2 or above. This facility is not available in previous versions of Java.

   2. Next, create your working java system. In general, you will want to put it into a package. For this example, I created a trivial HelloWorld application that prints out "Hello World" plus the first command line argument, and placed it into the package "psae". Therefore, the HelloWorld files (HelloWorld.class, HelloWorld.java) were located in the directory psae. I tested the system to make sure it worked before going on to the next step.

   3. In the directory in which the psae is located, created a file called "mainClass". This file contains a single line specifying where the main Class is to be found in the jar file. Note that I use the package specification. Here is the single line:

Main-Class: psae.HelloWorld

      Note: make sure you type a carriage return after this line; some windows systems need it and will report a "Failed to load Main-Class manifest attribute" error.

   4. Next, I create a jar file called psae.jar using the "jar" command in Java2. I use the "m" command line argument to specify the manifest file mainClass, which adds information to the jar file on where the main class will be found. Here is the jar command:

bertha:~ > jar cmf mainClass psae.jar psae

   5. Just for fun, and to check what's happened, I print the table of contents for the jar file I just created. Here's the command and its result:

bertha:~ > jar tf psae.jar
META-INF/
META-INF/MANIFEST.MF
psae/
psae/HelloWorld.java
psae/HelloWorld.class

   6. Having successfully created the jar file, I can now invoke java2 on it with the command line argument:

bertha:~ > java -jar psae.jar Philip
Hello World Philip
Avatar of Samooramad

ASKER

well I have JDK 1.4 which I downloaded with JBuilder...will that work for me?
>>To make a jar file executable, you need to specify where the "main" Class is in the jar file,
I'm not sure exactly what you mean..Al I know is I have a jar file and a manifest that says version 1.0 and in the second line it has my main class name..Is that what you mean?
I guess what you are saying is I should create the manifest myself then to make sure there is a carrige return right?
ASKER CERTIFIED SOLUTION
Avatar of Tommy Braas
Tommy Braas
Flag of Australia image

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
>> I guess what you are saying is I should create the manifest myself then to make sure there is a carrige return right?

True
>>I'm not sure exactly what you mean..Al I know is I have a jar file and a manifest that says version 1.0

Create your own Mainifest File and Place line something like following
Main-Class: psae.HelloWorld

where HelloWorld is a main class and psae package
>> well I have JDK 1.4 which I downloaded with JBuilder...will that work for me?

Yes it will
can I create a manifest file from an ordinary text file? using notepad or something?
>> can I create a manifest file from an ordinary text file? using notepad or something?

Yes you can. It is just a text file
ok I will try it
hasnt worked yet :(
sudhakar_koundinya,

You really shouldn't copy and paste from the internet, and then try to take credit for it! Provide a link instead: http://csdl.ics.hawaii.edu/~johnson/613f99/modules/04/jar-files.html , be honest.
>>You really shouldn't copy and paste from the internet, and then try to take credit for it! Provide a link instead:

I knoow that friend. Generally along with the matter I copied, I do post the link also. I forget that this time.

Generally  I do this because of two reasons.

1. Instead of opening two pages (Question thread and reference url), I do think that it will be easy to get the information with in same page

2. Some times in the older threads of EE, if I try to open the referenced links , I do get page not found errors. Like that I do missed maximum information (for the questions I answered and I asked)- Some times Very good Stuff. That is the reason, although content is duplicated, I do post  the content from URL.

Just because of not posting the link, this makes you to to think that I am not honest :((

Regards
Sudhakar
orangehead911 thanks for the link..the program was very helpfull

thanks
My pleasure! =-)