﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-毒菇求Buy-文章分类-JAVA</title><link>http://www.cnitblog.com/alsan/category/129.html</link><description>Not now, when?</description><language>zh-cn</language><lastBuildDate>Sat, 01 Oct 2011 17:42:47 GMT</lastBuildDate><pubDate>Sat, 01 Oct 2011 17:42:47 GMT</pubDate><ttl>60</ttl><item><title>Java Service Wrapper</title><link>http://www.cnitblog.com/alsan/articles/414.html</link><dc:creator>毒菇求Buy</dc:creator><author>毒菇求Buy</author><pubDate>Wed, 15 Jun 2005 11:03:00 GMT</pubDate><guid>http://www.cnitblog.com/alsan/articles/414.html</guid><wfw:comment>http://www.cnitblog.com/alsan/comments/414.html</wfw:comment><comments>http://www.cnitblog.com/alsan/articles/414.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/alsan/comments/commentRss/414.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/alsan/services/trackbacks/414.html</trackback:ping><description><![CDATA[<P style="FONT-SIZE: 12px; FONT-FAMILY: Verdana"><A href="http://wrapper.tanukisoftware.org/"><IMG height=50 alt="Java Service Wrapper" src="http://wrapper.tanukisoftware.org/buttons/UnderWrapperDuke144x50.png" width=144 border=0></A><A href="http://wrapper.tanukisoftware.org/doc/english/introduction.html">Java Service Wrapper</A>（以下简称JSW）是一个可以将Java应用程序封装成Windows服务（service）或Unix守护程序（daemon）的程序，而且是免费的。它可运行于：</P>
<UL style="FONT-SIZE: 12px; FONT-FAMILY: Verdana">
<LI>aix - AIX 
<LI>freebsd - FreeBSD 
<LI>hpux, hpux64 - HP-UX, 32 and 64-bit versions. 
<LI>irix - SGI Irix 
<LI>linux - Linux kernels; 2.2.x 2.4.x, 2.6.x. Known to work with Debian and Red Hat, but should work with any distribution. 
<LI>macosx - Macintosh OS X. 
<LI>osf1 - DEC OSF1. 
<LI>solaris - Sun OS, Solaris 7, 8. 
<LI>win32 - Windows NT, 2000, XP, and 2003.</LI></UL>
<P style="FONT-SIZE: 12px; FONT-FAMILY: Verdana">JSW的使用有三种方式：</P>
<OL style="FONT-SIZE: 12px; FONT-FAMILY: Verdana">
<LI>
<P>用WrapperSimpleApp class启动应用程序。这是使用JSW最简单的方式，也是推荐的方式。但使用这种方式有个问题，因为JSW是直接使用System.exit()退出JVM的，这等如使用者在应用程序运行期间直接按ctrl-c退出程序一样。如果应用程序在退出前需要执行clean up的话，需要自行登记shutdown hook，或不要使用这种方式。以这种方式配置<A href="http://www.jboss.org/">JBoss</A>的例子（<A href="http://wrapper.tanukisoftware.org/doc/english/integrate-simple-win.html">Win32</A>, <A href="http://wrapper.tanukisoftware.org/doc/english/integrate-simple-nix.html">Linux / UNIX</A>）。</P>
<LI>
<P>第二种方式是使用WrapperStartStopApp class。这种方式是给Tomcat之类的应用程序（即在一个类启动，但以另一个类结束的应用程序）。通常这类的应用程序都会在启动时打开一个server socket，用来等待要求程序结束的连接，当接收到要求结束的请求，“结束”类会被执行。而JSW就是在收到停止运行的要求时，直接执行这个“结束”类。以这这种方式配置<A href="http://jakarta.apache.org/tomcat/">Tomcat</A>的例子（<A href="http://wrapper.tanukisoftware.org/doc/english/integrate-start-stop-win.html">Win32</A>, <A href="http://wrapper.tanukisoftware.org/doc/english/integrate-start-stop-nix.html">Linux / UNIX</A>）。</P>
<LI>
<P>第三种方式，也是最复杂，最灵活的一种方式，也是唯一一种需要编程的方式。这种方式要写一个实现WrapperListener接口的类。有些功能是这种方式独有的，例如直接在程序中接收及回应系统控制事件（如启动及结束）。但这也增加了程序的复杂程度。如果不需要这些功能的话，还是使用第一种方式比较方便。以这种方式配置的<A href="http://wrapper.tanukisoftware.org/doc/english/integrate-listener.html">例子</A>。</P></LI></OL>
<P style="FONT-SIZE: 12px; FONT-FAMILY: Verdana">注：使用第一种方式最好不要使用JRE1.3.x或以上，因为1.2.x无shutdown hook的技持。如程序只能使用JRE1.2.x，就需要使用第二或第三种方式使用JSW。</P><img src ="http://www.cnitblog.com/alsan/aggbug/414.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/alsan/" target="_blank">毒菇求Buy</a> 2005-06-15 19:03 <a href="http://www.cnitblog.com/alsan/articles/414.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>