Signing java web start application by generated key – keytool

In this place I describe you how generate key and signing its your jar application as java web start program.  So first we generate key. If you would like to signinig java application: applet or java web start, you must generate your keystore. It used for it keytool – tool from java JDK.

So open command line in your OS and go in it to the bin folder in java installation. In my computer it is path :
C:\Program Files\Java\jdk1.7.0_51\bin

Write in console in one line( don’t type Enter):
keytool -genkeypair -dname “cn=doraprojects.net” -alias my_key_app  -keypass dorosia123 -keystore C:\Users\dora\Documents\mydorakey -storepass dora1234 -validity 357

Now click Enter key on keyboard.

In C:\Users\dora\Documents path you see my_app_key file – your generated key.

In second step You create MySignedApp project.

It is not special application. For our example it will be very simple program: yellow window. In main class file paste this code:

package mysignedapp;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JFrame;

public class MySignedApp {

    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable(){
       public void run(){           
            JFrame frame = new JFrame("My window");
            frame.getContentPane().setBackground(Color.yellow);
            frame.setSize(300,400);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);        
       }
       });
    }
}

If you would like to run this application as java web start you may right click on project node and choose from menu Set Configuration->Customize.

Select from Categories Web Start and choose Enable Web Start box. You may either set icon for your application. Click the Browse button and choose graphical file for it.

From Codebase select User definied… and in Codebase Preview field write path to folder on your web site with files your future application.

If we would like to sign application we must click the Customize button in Signing section.

In Signing window choose Sign by a specified key option. Click the Browse button net to Keystore Path field. Select your genereted key file: my_key_app.  In Keystore Password field write storepass password writing while generated key. In my app it is dora1234. In Key Alias field write my_key_app.  And in Key Password field write keypass value from generated key. In my application it is dorosia123. Click OK button.

In Properties Project window select Run from Categories section. Select from Configuration ComboBox Web Start element.

Select from Categories section Application. Filled data about your application.

Click OK button.

Click on Build and Clear tool.

And on Run tool.

Open in OS your projects content. in my project it is path:

C:\Users\dora\Documents\NetBeansProjects\MySignedApp\dist

Copy these file on your web server. In mine it is test2 folder. Call launch.html file.In your browser in address field write:

Http://doraprojects.net/test2/launch.html

You see:

Click the Launch button.

Click the OK button in Opened launch window with selecting open as Java web start launcher.

In Security Warning window select I accept box and click Run button. The application was running.