Link to home
Start Free TrialLog in
Avatar of thomas908
thomas908

asked on

run executable jar file

How can i run a executable jar file. If I double click it it asks me to select a program to open this with. Which program should i choose.
I am using windows.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

javaw.exe (or java.exe)
action should be configured as something like:

"C:\Program Files\Java\j2re1.4.2_05\bin\javaw.exe" -jar "%1" %*
wHICH would be present in your Jre/bin or JDK
Avatar of thomas908
thomas908

ASKER

Does not show anything. a prompt window opens and disappears.
I can run it using
 java -jar install.jar

 does that mean it is also executable and i can run it using doubleclick.
The Jar file also has to contain a special "Main-Class" entry in its manifest to be used this way.   In other words, the manifest.mf file has to contain something like :

    Main-Class: com.acme.MyMainClass

(replace my com.acme.MyMainClass with the qualified name of your class which contains the appropriate main)
t has the manifest.mf file. But not running on doubleclick. Although works with the command

java -jar install.jar
> does that mean it is also executable and i can run it using doubleclick.

you need to associate a jar file with an appropriate action like I posted above.

goto folder options>file types to add a new action.
you need to configure windows to handle jars, the jar itself is fine.
Right Click on the Jar file -> Click change-> Browser to the javaw file -> check the always use checkbox
and click Ok
All the jar files will be associated with Javaw
> I can run it using java -jar install.jar
> does that mean it is also executable and i can run it using doubleclick.

If its working through java -jar install.jar then try double click it. if it does not show up then :
Reinstall the installer for JRE or reinstall your JDK.

It happend to me before and I've done what I'm suggesting and it did work.

Hope that helps . . .
Javatm
i am getting the follwoing error

Could not find the main class. Program will exit
> Right Click on the Jar file -> Click change-> Browser to the javaw file -> check the always use checkbox
> and click Ok

that won't work, you need to congigure it as i specified earlier

I need to give this to the user to install the application. Does that she'll have to configure the same way
>>Does that she'll have to configure the same way
Sorry typo

Does that mean she'll have to configure the same way
> Does that mean she'll have to configure the same way

The JRE installation should look after it for you.
I have windows 2000 pro.
Selected folder options, file types and clicked New. It is asking me file extension and associated file type. But htere is no place to add
C:\Program Files\Java\j2re1.4.2_05\bin\javaw.exe" -jar "%1" %*
Have you tried my suggestion yet?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
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 am getting the follwoing error
>
> Could not find the main class. Program will exit
>

Did you produce the jar in question...?   If so, make sure to add the Main-Class attribute to the manifest (as I mentioned in my earlier post).   BTW - a single Jar can have more than one class with a main in it (you might have test mains in several classes).   This manifest attribute determines which class gets executed when you treat it as an executeable jar.


thanks everyone