Solved

java executable

Posted on 2004-10-15
16
256 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:Samooramad
  • 7
  • 6
  • 3
16 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12321485
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
0
 

Author Comment

by:Samooramad
ID: 12321528
well I have JDK 1.4 which I downloaded with JBuilder...will that work for me?
0
 

Author Comment

by:Samooramad
ID: 12321576
>>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?
0
 

Author Comment

by:Samooramad
ID: 12321665
I guess what you are saying is I should create the manifest myself then to make sure there is a carrige return right?
0
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 500 total points
ID: 12321672
Hi Samooramad,

You can download InstallAnyhere Now! for free from www.installanywhere.com. It will allow you to, not only create an executable, but also create an installer for your program.

Cheers!

\tt
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12321903
>> I guess what you are saying is I should create the manifest myself then to make sure there is a carrige return right?

True
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12321925
>>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
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12321930
>> well I have JDK 1.4 which I downloaded with JBuilder...will that work for me?

Yes it will
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Samooramad
ID: 12322068
can I create a manifest file from an ordinary text file? using notepad or something?
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12322099
>> can I create a manifest file from an ordinary text file? using notepad or something?

Yes you can. It is just a text file
0
 

Author Comment

by:Samooramad
ID: 12322520
ok I will try it
0
 

Author Comment

by:Samooramad
ID: 12324537
hasnt worked yet :(
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 12324876
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.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12326021
>>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
0
 

Author Comment

by:Samooramad
ID: 12330746
orangehead911 thanks for the link..the program was very helpfull

thanks
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 12335157
My pleasure! =-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SPLUNK REST  API call to Splunk to create and index? 2 67
sumDigits  challenge 7 60
topping2 challenge 13 58
word0 challenge 3 56
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now