對於記錄:
我必須註冊使用procrun這個實現?但是,由於procrun可以將任何程序註冊爲windows服務,因此似乎並沒有實現界面的重要性。
是的服務需要使用prunsrv在Windows中註冊。例如通過以下調用:
prunsrv.exe //IS//MyTestService^
--DisplayName="My Test Service" --Description="Doesn't really do anything"^
[email protected]@[email protected]@\prunsrv.exe^
--Startup=manual^
--Jvm=auto^
--Classpath="@@[email protected]@"^
--StartMode=jvm^
--StartClass==com.stackoverflow.questions.31556478.ServiceLauncher^
--StartParams="@@[email protected]@"^
--StartMethod=start^
--StopMode=jvm^
--StopClass=com.stackoverflow.questions.31556478.ServiceLauncher^
--StopMethod=stop
在此之後,服務可以通過
prunsrv //ES//MyTestSevice
什麼開始將是一個靜態的啓動的正確行爲(字符串[ ] args)方法?
測試這兩個變體,只有實現工作,停留在開始方法並沒有產生額外的線程。這是一個啓動器實現,可以註冊上述prunsrv調用看起來像這樣(沒有任何保證):
package com.stackoverflow.questions.31556478;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ServiceLauncher
{
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceLauncher.class);
private static SomeServer mServer;
public static void start(final String[] args)
{
LOGGER.debug("Start called: {}", Arrays.toString(args));
try
{
mServer = new SomeServer(args);
mServer.start();
}
catch (final Exception e)
{
LOGGER.error("Terminating due to Exception: ", e);
}
}
public static void stop(final String[] args) throws Exception
{
LOGGER.debug("Stop called: {}", Arrays.toString(args));
synchronized (ServiceLauncher.class)
{
if (mServer != null)
{
mServer.stop();
}
}
}
}
來源
2015-09-02 11:57:39
dpr