How to run Java programs by clicking on their icon on Windows?

Since it is Java based and has a GUI, the obvious answer is to deploy it using Java Web Start.

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

By 'desktop integration' read desktop shortcuts and menu items on supported platforms.

Desktop Icons on Windows 7

The 2 icons on the right (JotPad & Star Zoom Animation) are both Java based apps., installed using Java Web Start. Since JotPad is sand-boxed, the user will be prompted as to whether to create the shortcut. That choice is not offered for apps. with higher permission levels, so it would make more sense to install/remove the shortcuts and menu items using the IntegrationService - which allows an app. (after prompting the user) to create/remove them at run-time.


There are number of options:

  1. Create an executable jar of your project. for this jar to work you have to have javaw as default application to open it.
  2. Create an exe of your project.
  3. Create a bat file which runs your jar file.

Take a look at this: How can I convert my Java program to an .exe file?


you need to create exe from the java program.

Creating executable jar files

  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
    

While the others mention excellent choices like creating a native executable, there is another useful method: creating a shortcut.

  • Right click your desktop, expand the "New" option, and click on "Shortcut".
  • Type "javaw.exe". Click next.
  • Name it whatever you want. Click done.
  • You'll notice the newly created shortcut on your desktop. Right click it and choose "Properties"
  • In the "Target" textfield, append "-jar path-to-your-jar.jar" where you replace "path-to-your-jar.jar" with the actual path to your jar
  • You can also now optionally change the icon to whatever icon you want

This shortcut can be pinned to the taskbar and be used from anywhere (considering you provided an absolute path to your JAR).