windows服务未启动

yquaqz18  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(233)

我使用prunsrv为创建windows服务进行了以下配置。我尝试了64位和32位版本的prunsrv,但都没有成功。日志文件stdout.log和stderr.log创建时没有任何内容。提前感谢您对如何让它工作的任何建议。

prunsrv install TEST_SERVICE ^
--StartPath=D:\test\application ^
--Classpath=D:\test\lib\test-7.3.6.jar ^
--StartMode=jvm --StartClass=com.test.AppServiceEntryPoint ^
--StartMethod=serviceMain ^
--StopMode=jvm ^
--StopMethod=serviceRequest ^
--StopParams=1 ^
--StdOutput=stdout.log --StdError=stderr.log ^
--Jvm="C:\Program Files\Java\jdk-15.0.1\bin\server\jvm.dll" ^
--Startup=auto

下面是appserviceentrypoint类

public class AppServiceEntryPoint implements Service {

    private int returnCode = 0;
    private volatile boolean shutdown = false;

    Process p;

    ConfigurableApplicationContext context;

    private static final Logger logger = LoggerFactory.getLogger(EmenuAppServiceEntryPoint.class);

    boolean isExitCalled;

    @Override
    public int serviceRequest(int request) throws ServiceException {

        logger.debug("service request : {}", request);

        if (request == SERVICE_CONTROL_STOP || request == SERVICE_CONTROL_SHUTDOWN) {
            logger.debug("stop command received");

            context.stop();

            logger.debug("stopped successfully");

            shutdown = true;
            isExitCalled = true;
        }
        return 0;
    }

    @Override
    public int serviceMain(String[] arg0) throws ServiceException {

        logger.debug("service main");
        logger.debug("Java Version - {}",System.getProperty("java.version"));
        new Thread() {
            public void run() {
                try {
                    context = ServerUtil.startServer();
                    context.registerShutdownHook();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            };
        }.start();

        while (!shutdown) {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
            }

        }

        if (isExitCalled)
            System.exit(0);

        logger.debug("exit service main");
        return returnCode;
    }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题