File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""Executables" Win2000 - a solution" Watch ""Executables" Win2000 - a solution" New topic

"Executables" Win2000 - a solution

Peter Simard
Ranch Hand

Joined: Oct 31, 2001
Posts: 54
Can you launch a Java application just by double-clicking a jar or class file?
How do you set this up, without resorting to batch files?

Absolutely! You simply need to create the right file association and command-string for the target extension (in our case, �.jar� and �.class�). I tested this under Windows 2000, and found that it works�


To create a "double-clickable" jar file that automatically executes:

(1) Get or change the file assocation via
the "assoc" command.

assoc .jar=jarfile

(2) Create an open "command string" via the
"ftype" command.

ftype jarfile="C:\jdk1.3\bin\java.exe" -jar %1

You can do much the same with �.class� files. For more information on these commands, go to the command-line and type in:

assoc /?
ftype /?

Or select F1 from the Windows desktop, and look them up.


(1) You can double-click any jar file, and it will execute
(provided it has a file with an entry point).

(2) You can also execute a jar by typing its full name on
the command-line, as in:


See NOTE below for additional details...

Either method causes Windows to execute the following

C:\jdk1.3\bin\java.exe" -jar %1

where %1 is the name of the jar file you double-clicked.
For example, given the file named "fubar.jar", the following
command is issued:

C:\jdk1.3\bin\java.exe" -jar fubar.jar

NOTE: you can obviate the need to type in the extension
by modifying your PATHEXT environment variable.
This environment variable stores the extensions
of all files that can be executed, including
EXE and BAT. You can add JAR to the lot by
typing the following at the command-line:


The same way you set the PATH environment variable,
which stores the directories that should be
searched for executables.

PAS<br /><br />2b || !2b
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: "Executables" Win2000 - a solution
It's not a secret anymore!