Boot application with Windows

4

I have a desktop Java application, and I need it to always be started along with Windows (like a windows service for example). This application should be running in the background and always be open because it will perform tasks periodically using Quartz.

Would you like to know how I can get started and keep running? If there is a failure and the application does not start, how do I perform a monitoring to try to run it again? The process should be automatic as I will generate the installer of this application using InnoSetup and customers will download the application and install it.

Already warning that I did searches, I saw about the Java Service Wrapper, but I do not know how to make it keep the application always running and monitor tb. I would just like an orientation on.

    
asked by anonymous 11.03.2016 / 00:58

2 answers

1

You can create a key in Regedit (Windows Registry) through Java itself using the following code:

 String valor = "\"javaw -jar " + System.getProperty("usuário.dir") + "\meuJar.jar\"";
WinRegistry.writeStringValue(WinRegistry.HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", "meu Jar aplicativo exe", value);

And if you want to remove your key created to boot the application with Windows:

WinRegistry.deleteValue(WinRegistry.HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", "meu Jar aplicativo exe");

Or you can also create a .bat file and place this code inside to create a key and make your application start along with Windows:

javaw -Xmx200m -jar C:\Caminho\para\jarfile\ArquivoJar.jar

And also if this has not helped you, follow this link .

    
12.06.2016 / 07:55
0

You can create a service in Windows as follows, at the command line, by running admin :

sc create meuServico binPath= "java -jar C:\to\my\service.jar" start= auto
                             ^^                                      ^
                       espaço||aspas                           espaço|

Preserve spaces and quotation marks added, as in the example above.

The parameter start= auto indicates the automatic startup of the service when the machine is turned on.

    
11.03.2017 / 22:29