1

Windows サービスとして単純な Java アプリケーションを実行しようとしています。これは私のメインクラスファイルです。5 秒ごとに時間を印刷し、1 分後に停止しようとしています。パッケージ名は samPack です。

package samPack;
import java.util.Date;


public class Time {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Thread thread = new Thread()
        {

            public void run()
            {
                long start = System.currentTimeMillis();
                long end = start + 60*1000;


                    while (System.currentTimeMillis() < end){
                        //System.out.println("Hello World");
                        Date date = new Date();
                        System.out.println("Ram Test   ---- >  "+date.toString());

                        try
                        {
                            Thread.sleep(5000); // 1 second
                        } catch (Exception e)
                        {
                            e.printStackTrace();
                        }
                    }

            }
        };
        thread.start();

    }

}

これを Windows サービスにするために、Tanuki Software の Java Service Wrapper をダウンロードしました。フォルダをデスクトップに解凍します。上記のコード用に実行可能な jar ファイルを作成し、それを Java サービス Wrapper の bin フォルダーと lib フォルダーに貼り付けました。DemoApp.bat が bin フォルダーで失敗する run.bat に変更し、そのファイルで変数 WRAPPER_CONF_DEFAULT を ../conf/wrapper.conf に変更しました。

Wrapper.conf ファイルで、これらは私が行った変更です

# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=samPack.Time

# Java Classpath (include wrapper.jar) Add class path elements as
wrapper.java.classpath.1=../lib/wrappertest.jar
    wrapper.java.classpath.2=../lib/wrapper.jar
    wrapper.java.classpath.3=../lib/sam.jar

# Name of the service
wrapper.name=samtestservice

# Display name of the service
wrapper.displayname=Sam Test Service

# Description of the service
wrapper.description=Sam Test Service Decs

# Mode in which the service is installed. AUTO_START, DELAY_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START

バットファイル run.bat を実行すると、コンソールで実行され、以下の結果が表示されます。

wrapper  | Launching a JVM...
jvm 1    | Ram Test   ---- >  Mon May 05 18:18:59 IST 2014
jvm 1    | Ram Test   ---- >  Mon May 05 18:19:04 IST 2014
jvm 1    | Ram Test   ---- >  Mon May 05 18:19:09 IST 2014
jvm 1    | Ram Test   ---- >  Mon May 05 18:19:14 IST 2014
jvm 1    | Ram Test   ---- >  Mon May 05 18:19:19 IST 2014
jvm 1    | Ram Test   ---- >  Mon May 05 18:19:24 IST 2014
wrapper  | Startup failed: Timed out waiting for a signal from the JVM.
wrapper  |
wrapper  | ------------------------------------------------------------------------
wrapper  | Advice:
wrapper  | The Wrapper consists of a native component as well as a set of classes
wrapper  | which run within the JVM that it launches.  The Java component of the
wrapper  | Wrapper must be initialized promptly after the JVM is launched or the
wrapper  | Wrapper will timeout, as just happened.  Most likely the main class
wrapper  | specified in the Wrapper configuration file is not correctly initializing
wrapper  | the Wrapper classes:
wrapper  |     samPack.Time
wrapper  | While it is possible to do so manually, the Wrapper ships with helper
wrapper  | classes to make this initialization processes automatic.
wrapper  | Please review the integration section of the Wrapper's documentation
wrapper  | for the various methods which can be employed to launch an application
wrapper  | within the Wrapper:
wrapper  |     http://wrapper.tanukisoftware.com/doc/english/integrate.html
wrapper  | ------------------------------------------------------------------------

bat ファイルを実行してサービスをインストールしましたが、サービスを開始できません。サービス開始。何がうまくいかないのですか?

4

1 に答える 1

2

wrapper.java.mainclass=samPack.Timeに変更wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp

新しい行を追加しますwrapper.app.parameter.1=samPack.Time

詳細はタヌキのウェブサイトにあります: http://wrapper.tanukisoftware.com/doc/english/integrate-simple-win.html

于 2014-05-05T14:22:30.673 に答える