Java服务包装器 - 保持运行和停止

时间:2014-04-01 03:41:57

标签: java windows service

这是日志文件,显然是服务工作。创建的行文件是从我的程序打印出来的。但它只是不能留下来。我的配置有什么错误?已经尝试了一段时间,但没有任何线索

STATUS | wrapper  | 2014/04/01 11:38:58 | Launching a JVM...
INFO   | jvm 1    | 2014/04/01 11:38:58 | file created
ERROR  | wrapper  | 2014/04/01 11:38:58 | JVM exited while loading the application.
STATUS | wrapper  | 2014/04/01 11:39:02 | Launching a JVM...
INFO   | jvm 2    | 2014/04/01 11:39:03 | file created
ERROR  | wrapper  | 2014/04/01 11:39:03 | JVM exited while loading the application.
STATUS | wrapper  | 2014/04/01 11:39:07 | Launching a JVM...
INFO   | jvm 3    | 2014/04/01 11:39:07 | file created
ERROR  | wrapper  | 2014/04/01 11:39:07 | JVM exited while loading the application.
STATUS | wrapper  | 2014/04/01 11:39:12 | Launching a JVM...
INFO   | jvm 4    | 2014/04/01 11:39:12 | file created
ERROR  | wrapper  | 2014/04/01 11:39:12 | JVM exited while loading the application.
STATUS | wrapper  | 2014/04/01 11:39:17 | Launching a JVM...
INFO   | jvm 5    | 2014/04/01 11:39:17 | file created
ERROR  | wrapper  | 2014/04/01 11:39:17 | JVM exited while loading the application.
FATAL  | wrapper  | 2014/04/01 11:39:17 | There were 5 failed launches in a row, each lasting less than 300 seconds.  Giving up.
FATAL  | wrapper  | 2014/04/01 11:39:17 |   There may be a configuration problem: please check the logs.
STATUS | wrapper  | 2014/04/01 11:39:17 | <-- Wrapper Stopped

代码

    public static void main(String[] args) throws IOException {
    ServerSocket listener = new ServerSocket(3002);
        System.out.println("server started");
    try {
        while (true) {
            Socket socket = listener.accept();
            try {
                PrintWriter out =new PrintWriter(socket.getOutputStream(), true);
                out.println(new Date().toString()+"\ntest");
            } finally {
                socket.close();
            }
        }
    }
    finally {
        listener.close();
    }
}

配置文件

#********************************************************************
# Wrapper Java Properties
#********************************************************************
# Java Application
#  Locate the java binary on the system PATH:
wrapper.java.command=java
#  Specify a specific java binary:
#set.JAVA_HOME=/java/path
#wrapper.java.command=%JAVA_HOME%/bin/java

# Tell the Wrapper to log the full generated Java command line.
#wrapper.java.command.loglevel=INFO

# 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=HelloWorldServer

# Java Classpath (include wrapper.jar)  Add class path elements as
#  needed starting from 1
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../lib/classes
wrapper.java.classpath.3=../dist/HelloWorldServer.jar

# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib

# Java Bits.  On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
wrapper.java.additional.auto_bits=TRUE

# Java Additional Parameters
wrapper.java.additional.1=

# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3

# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64

# Application parameters.  Add parameters as needed starting from 1
#wrapper.app.parameter.1=HelloWorldServer

1 个答案:

答案 0 :(得分:0)

您需要将主类设置为wrapper classes之一。基本上将以下内容添加到您的wrapper.conf

wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
wrapper.app.parameter.1=HelloWorldServer