JNLP Example

Java Web Start is the technology that allows a user to run java from their local device. The software that is run is loaded from a server via a directive in a JNLP file on the server. It is downloaded to the client.

Test class…

import javax.swing.*;
import java.sql.*;

public class JNLPTest extends JFrame {

  private static final long serialVersionUID = 4968624166243565348L;

  private static JTextArea label = new JTextArea();

  public JNLPTest() {
    super("JNLP Test");
    this.setSize(700, 400);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(null);
  }

  public void addButtons() {
	label.setSize(400, 180);
	label.setLocation(160, 100);
	this.getContentPane().add(label);
  }

  public static void main(String[] args) throws Exception {
	try {
  	  Class.forName("oracle.jdbc.driver.OracleDriver");
	  Connection conn = DriverManager.getConnection("jdbc:oracle:thin:" + args[0] + "/" + args[1] + "@" + args[2] + ":" + args[3] + "/" + args[4]);
	  ResultSet rst = conn.createStatement().executeQuery("select distinct machine from gv$session");
	  StringBuffer sb = new StringBuffer();
	  while (rst.next()) {
		sb.append(rst.getString(1) + '\n');
	  }
	  label.setText(sb.toString());
    }
    catch (Exception e) {
	  label.setText(e.getMessage());
	  e.printStackTrace();
	}
	JNLPTest exp = new JNLPTest();
	exp.addButtons();
	exp.setVisible(true);
  }
}

JNLP file…




  
    JNLP Test
    EXPRESS
    
    JNLP Test
  

  
    
  

  
    
    
    
  

  
    username
    password
    dbhost
    1521
    servicename.domain
  

You can build the java class above, as well as sign it, with what is below..

c:\Users\showard\Downloads>del testkeys

c:\Users\showard\Downloads>javac JNLPTest.java

c:\Users\showard\Downloads>jar -cvf JNLPTest.jar JNLPTest.class
added manifest
adding: JNLPTest.class(in = 2290) (out= 1309)(deflated 42%)

c:\Users\showard\Downloads>keytool -genkey -keystore testkeys -alias welcome
Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:
What is the name of your organizational unit?
  [Unknown]:
What is the name of your organization?
  [Unknown]:
What is the name of your City or Locality?
  [Unknown]:
What is the name of your State or Province?
  [Unknown]:
What is the two-letter country code for this unit?
  [Unknown]:
Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
  [no]:  yes

Enter key password for 
        (RETURN if same as keystore password):

c:\Users\showard\Downloads>jarsigner -keystore testkeys JNLPTest.jar welcome
Enter Passphrase for keystore:
jar signed.

Warning:
The signer certificate will expire within six months.
No -tsa or -tsacert is provided and this jar is not timestamped. Without a times
tamp, users may not be able to validate this jar after the signer certificate's
expiration date (2016-12-13) or after any future revocation date.

c:\Users\showard\Downloads>jarsigner -keystore testkeys ojdbc6.jar welcome
Enter Passphrase for keystore:
jar signed.

Warning:
The signer certificate will expire within six months.
No -tsa or -tsacert is provided and this jar is not timestamped. Without a times
tamp, users may not be able to validate this jar after the signer certificate's
expiration date (2016-12-13) or after any future revocation date.

c:\Users\showard\Downloads>

Deploy the JNLPTest.jar and ojdbc6.jar (available for download on the internet), as well as the JNLP file to your application server. Request the JNLP file in your browser, and if you have java properly configured in the browser, it should execute the class and print the list of distinct machines logged into the Oracle database you configure in the JNLP file.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.