Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

java executable

Posted on 2004-10-15
16
Medium Priority
?
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 1500 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
 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 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