Java Web Start

Source: Internet
Author: User
Tags openssl commands
Written by: Gui jingqiu
Reference: http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/contents.html

Preface
The project is required, so I studied it a few days ago and spent 1.5 days without wasting any time. I would like to share it with you.

Application
JWS is mainly used to publish applications. It mainly writes JNLP files. When users access JWS through HTTP, the applications are automatically installed on the local machine. In the future, JWS will be automatically updated. It can be said that it is a new way to release software. (Of course, the other party must have a JVM)

Procedure

Compile a test file and compress it into a hello. jar package.

  1.  
  2. // File hellojnlp. Java
  3. ImportJavax. Swing .*;
  4. ImportJava. AWT .*;
  5. ImportJava. AWT. event .*;
  6. ImportJava. Io .*;
  7. ImportJava.net .*;
  8.  
  9. Public ClassHellojnlpExtends Jframe Implements Actionlistener{
  10. /**
  11. *
  12. */
  13. Private Static Final LongSerialversionuid = 1l;
  14.  
  15. PublicHellojnlp (){
  16. Super("Hello JNLP ");
  17. StringLoadedfrom =This. Getclass (). getclassloader (). tostring ();
  18. JlabelJl =New Jlabel("Loaded by" + loadedfrom );
  19. JeditorpaneJtp =New Jeditorpane("Text/plain", "version 1.1.2 ");
  20. JbuttonBB =New Jbutton("Write native file ");
  21. Getcontentpane (). Add (JL,Borderlayout. North );
  22. Getcontentpane (). Add (jtp,Borderlayout. Center );
  23. Getcontentpane (). Add (BB,Borderlayout. South );
  24. BB. addactionlistener (This);
  25. BB. setactioncommand ("wnf ");
  26. }
  27.  
  28. Public Static VoidMain (String[] ARGs ){
  29. JframeF =NewHellojnlp ();
  30. F. setbounds (100,100,325,250 );
  31. F. setdefaclocloseoperation (dispose_on_close );
  32. F. setvisible (True);
  33. F. addwindowlistener (New Windowadapter(){
  34. Public VoidWindowclosed (WindoweventE ){
  35. System. Out. println ("shutting down ...");
  36. System. Exit (0 );
  37. }
  38. });
  39. }
  40.  
  41. Public VoidActionreceivmed (ActioneventArg0 ){
  42. // System. Out. println (arg0.getactioncommand ());
  43. Try{
  44. FileoutputstreamFos =New Fileoutputstream("Abcfile ");
  45. Try{
  46. FOS. Write (0 xFFFF );
  47. FOS. Close ();
  48. System. Out. println ("Write File OK ");
  49. }Catch(IoexceptionE ){
  50. // Todo auto-generated Catch Block
  51. E. printstacktrace ();
  52. }
  53. }Catch(FilenotfoundexceptionE ){
  54. // Todo auto-generated Catch Block
  55. E. printstacktrace ();
  56. }
  57. Try{
  58. Socket sock =NewSocket (Inetaddress. Getbyname ("www.cctv.com"), 80 );
  59. Sock. Close ();
  60. System. Out. println ("socket create OK ");
  61. }Catch(UnknownhostexceptionE ){
  62. // Todo auto-generated Catch Block
  63. E. printstacktrace ();
  64. }Catch(IoexceptionE ){
  65. // Todo auto-generated Catch Block
  66. E. printstacktrace ();
  67. }
  68. }
  69. }
  70.  

This application tests the local file system and uses local network resources when clicking jbutton. (Compilation and packaging process omitted)

Next, I had a hard time working for a day. How can I perform certificate authentication on the jar so that the application can be installed to the user to operate on local resources. Originally, I used JDK's keytool to generate a certificate, but it was only available for half a year. Later I decided to apply for a certificate from the official website, which would cost 800 $/year. Finally, we should use OpenSSL for our own purposes, but the process is quite complicated and cannot control the process well. The main reason is that we are not familiar with OpenSSL commands. After a day of hard work, I finally found that Java itself could generate a user-defined deadline for use. Ah...

Generate a new keystore
Keytool-genkey-keystore mykeystore-alias myself

Generate a private certificate
Keytool-selfcert-alias myself-keystore mykeystore-validity 365

Note-validity 365 indicates the validity period of the certificate, which is 1 year. You can define a larger value by yourself.

Sign jar
Jarsigner-keystore mykeystore hello. jar myself

In this way, the signature is complete. Finally, write a JNLP description file hello. JNLP.

  1.  
  2. <? XML version = "1.0" encoding = "UTF-8"?>
  3. <! -- File hello. JNLP -->
  4. <JNLP codebase = "http: // 192.168.1.6: 81/JNLP /"
  5. Href = "http: // 192.168.1.6: 81/JNLP/Hello. JNLP">
  6. <Information>
  7. <Title> Hello </title>
  8. <Vendor> tech tips sample May 2001 </vendor>
  9. <Icon href = "/JNLP/qq.jpg"/>
  10. </Information>
  11. <Resources>
  12. <J2se version = "1.3 +"/>
  13. <Jar href = "/JNLP/Hello. Jar"/>
  14. </Resources>
  15. <Security>
  16. <All-permissions>
  17. </Security>
  18. <Application-Desc main-Class= "Hellojnlp"/>
  19. </JNLP>
  20.  

I put jar and JNLP on the host of 192.168.1.6 and access them through 81port. You can modify the above information as needed.

Test it. Http: // 192.168.1.6: 81/JNLP/hello. if JNLP is opened with IE, a basket that you accept will pop up immediately, indicating that this individual or company is untrusted (because it is not a certificate applied by an authority, AH ), click "accept" to run the program in jar normally and use the local function normally.

Similarly, the applet can operate locally after the above steps, just like the signature ActiveX, or like some of IE's self-Signed ActiveX (which is actually a system vulnerability, huh, huh ), please criticize and correct.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.