I'm currently using an IDE for writing a java application and testing it. In the IDE, I can run the application and see how it works. However, how would I run the application using a shortcut, or a jar file? For example, in order to run my WAMP server, I run the wamp.exe file in the WAMP directory. So, I'm running a single file which launches the entire program. How do I achieve this sort of thing with a java application? I've heard about using a jar file, but I'm unsure about whether that would be the proper way to do this or not.
4 Answers
It depends on the IDE you are using. With eclipse for example, you open up the file tab, select export, open java in the tree, and select runnable jar file. Then fill the interface out and your good to go.

- 4,228
- 1
- 23
- 34
-
Any advice on how to do this without Eclipse? Also, are .exe files not favorable for java applications? – fvgs Feb 03 '13 at 05:52
-
The best way to run a java application (and the only simple way that i know of) is to use a jar file, also .exe files are usually pre-compiled while java is not. and Eclipse is the only IDE i use so i don't know about any others, but i would assume that you would probably follow roughly the same procedure. – Neil Locketz Feb 03 '13 at 05:54
-
@Wolfram which IDE are you using? – Abubakkar Feb 03 '13 at 05:55
-
I'm currently using jGRASP on a school computer, on which I can't install Eclipse. It seems like it may have a jar creation option I'll look into. – fvgs Feb 03 '13 at 05:58
If you are using Eclipse, then you can export your application as a single jar file and run it directly by double clicking
In the Package Explorer view:
- Right click on your project
- Go to "Export"
- Click on "Export as Runnable Jar"
And you are done
And if you are using Netbeans, then follow these steps:
- Right click on your project
- Click on "Clean and Build"
- Now got the directory where your netbeans projects are created( usually it should be "C:\Users\your_user_name\Documents\NetBeansProjects"
- Open the directory of your project (directory with the name of your project name)
- Open "dist" folder and you'll find the jar file of your application/project there.

- 15,488
- 8
- 55
- 83
Java Web Start is the easiest way to add shortcuts for a desktop app.
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
See also
This answer - the 2 icons on the right "JotPad" & "Star Zoom Animation" are icons installed by JWS.

- 1
- 1

- 168,117
- 40
- 217
- 433
You can also, just for fun, create a launcher in C++ that launches your executable(the way Limewire did it). A simple console mode C program is given below.
#include <stdlib.h>
int main(int argc, char *argv[]) {
system("java YourProgramClassFileNameHere");
return 0;
}
An advanced methodology would require CreateProcess()
in win32API or in JNI for your platform.
You can convert it to an executable Jar file(See Abu's answer)
You can also, create a bat file which can run your program: (Windows only)
@echo off
start java YourProgramClassFileNameHere
Or a shell script(BASH)
Also, see here run a executable jar from c++ code

- 1
- 1

- 25,375
- 5
- 50
- 78
-
1Just to satiate my own curiosity how would you write the launcher i know some C++ and would like to know how to do this ^_^. – Neil Locketz Feb 03 '13 at 05:56
-
@NeilLocketz I prefer the JNI way mostly because of the amount of control I get while launching a Jar file.. :-), I can even display a _cool_ splash screen(before loading the JVM) – Aniket Inge Feb 03 '13 at 06:06
-
Really, that sounds awesome. I'm most definitely going to look into it thanks :). – Neil Locketz Feb 03 '13 at 06:11