Reputation: 21982
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.
Upvotes: 0
Views: 2181
Reputation: 168825
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..
This answer - the 2 icons on the right "JotPad" & "Star Zoom Animation" are icons installed by JWS.
Upvotes: 1
Reputation: 15664
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:
And you are done
And if you are using Netbeans, then follow these steps:
Upvotes: 1
Reputation: 25705
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
Upvotes: 0
Reputation: 4318
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.
Upvotes: 4