I would like to run a Java application as a service. Unfortunately, I am limited in that I can't use something like the Java Service Wrapper (which does appear to be an excellent tool).
Is there any way of running an executable JAR, as a service, without relying on external applications? I currently have the service installed, but it fails to start. This is where I am getting stuck and I haven't been able to find anything on Google other than information about the JSW.
There's an LGPL clone of the Java Service Wrapper: http://yajsw.sourceforge.net
BTW, IANAL, but I suspect that JSW people are spreading FUD, and their software can be used to service-enable commercial applications under GPL license, just like one can gzip a commercial app for redistribution. I could be completely wrong about this, though :)
Another option, Apache Commons Daemon's procrun.
See http://commons.apache.org/daemon/
A program that should run as windows service must provide certain functions that the windows service manager uses to communicate with that service.
As long as there is no JVM that implements this functions directly (and I know of none) you will need some kind of wrapper.
I have successfully used srvany for a java based windows service (Basically it allows to run any program as windows service and it works fine with java)
You can use NSSM like this:
nssm install MyService "%JAVA_HOME%\bin\java.exe" -jar "path\to\the\file.jar"
I haven't tried it (yet), but Launch4j looks like it could suit your needs.
one more option winrun4j. the license is eclipse's CPL.
The most simple way I found was RunAsService.
A co-worker recommended a tool called SC, but I did not try it.
JSmooth can do it, and it is scriptable with ant.
Related
I have a Java Spring Boot application which I would like to run as a service, ideally in Mac, Windows and Linux. It should run 24/7 and be robust i.e. restart itself if it crashes.
Does anyone know the current best practice way of achieving this?
In order to make an app as a service it should confront to some Interface defined by Microsoft. Here it is:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms685942(v=vs.85).aspx
This is not the easiest solution and will make you app platform dependent. There are some wrappers that make what you want possible.
Check the Java Service Wrapper
https://wrapper.tanukisoftware.com/doc/english/introduction.html
It has options to wrap the app as windows service and unix daemon. I am not sure about macOs. There are other similar wrappers too
Best practice1 is to use the best practice solution for each platform. Unfortunately, that means different things for different platforms; e.g.
on Window, use the Windows Service mechanism
on UNIX / Linux, write a service script that uses the distro's native "init" framework
on Mac OSX, you typically use something like Automator to create a ZIP file that implements the service.
Unfortunately, in the UNIX / Linux case there are a number of different init frameworks, depending on the vintage; see this Wikipedia page.
Another answer mentions the Java Service Wrapper. I don't know how well it works with different Linux "init" frameworks, but it looks like it provides a one-size-fits-all init script written in "sh". It should be usable with systemd, though you won't get the full benefits of that framework.
1 - But read James Bach's No Best Practices article.
I am wondering if there is a simple wrapper class/library for the Tomcat Manager application. I am writing a script to deploy my war to a remote instance of Tomcat (hosted on AWS).
I know I can directly use HTTP to communicate with the manager script interface, but I thought this would be a common problem, so I do not want to re-invent the wheel. I found a python solution here, and this question talks about using curl, but I can't find a java solution (which is funny, Tomcat is used by Java developers, not bash developers!) Can someone please point me in the right direction?
I found what I needed in this answer. I can use the Tomcat Ant library. In order to do so, all I need is the catalina-ant.jar from $CATALINA_HOME/lib in my project's dependencies.
org.apache.catalina.ant.DeployTask task = new org.apache.catalina.ant.DeployTask();
task.setUrl("http://localhost:8084/manager");
task.setUsername("managerLogin");
task.setPassword("managerPassword");
task.setPath("/UrlToYourDeploadingProject");
task.setWar(new File("c:/Project.war").getAbsolutePath());
task.execute();
All of the solutions I found on stackoverflow suggest wrappers to register java application as windows service. My requirement is totally different. Please don't suggest wrappers for the purpose. The question is very simple I have java executable and I want to register it as windows service.
Phyiscal Path
Service Properties
Unfortunately we don't have backup of previous setup that installed it as windows service at the first place. Do I need some setup program or anything like that.
Not necessarily.
It is difficult to advise you on precisely what you need to do without more information on what you actually still have; e.g. an application installer, application JAR files, wrapper scripts, etc. Alternatively, if you told us what the application was, then maybe we could give you some hints on where to get installers, etc.
However, I can tell you definitely that registering java.exe or javaw.exe directly as a Windows Service will not work. These are not the executables for your Java application. Rather they executables for as Java Virtual Machine that will run your (real) Java application.
It is so easy task in case of Visual Studio. I want same support in Eclipse or anything else.
Well Java doesn't work like that. Java compiles to platform independent bytecode files, not to platform-specific native code. Sure, there are third party tools to generate exe's. However, using them is neither necessary, or desirable:
Why is creating an .exe from a java program not recommended?
(And asking for recommendations on what tools to use to do this is off-topic.)
Finally, if you take an arbitrary Java program and turn it into an ".exe" file, it won't necessarily be immediately registerable as a Windows service. This Q&A talks about turning an ".exe" into a Windows Service.
Create Windows service from executable
However, I can't tell you if the advice given there is appropriate for an ".exe" file created from an arbitrary Java app by some unspecified 3rd-part tool.
My recommendation:
If you are starting from scratch, use a Java Service Launcher / Wrapper.
If not, talk with whoever supplied and/or installed this application in the first place.
If you can't find any information about the application and where it came from, or if the vendor has gone out of business ... you need to urgently look for an alternative.
We're making a login client in Java for a school project.
It uses SSH to connect a local server to allow for internet connection, for the convinience of our users we would like to be able to make an "open on startup" function.
We know that this could be done by cron/damon jobs in linux, and by service/registry methods in windows... We don't know about OS X.
We would like to CODE the solution in java, each solution doesn't have to be for all 3 OS' but just one, then they can execute when needed.
Any help would be appriciated. :-)
Regards
Martin
YAJSW (Yet Another Java Service Wrapper) could provide this functionality, and is licensed under the LGPL.
http://yajsw.sourceforge.net/
You'd want to create your configuration during installation I suppose, and in install/uninstall the service when the user toggles the checkbox.
You'll also find a feature matrix of other options for achieving the same thing at http://yajsw.sourceforge.net/#mozTocId284533
And for you interest, under the hood on OS X the system this uses is called launchd.
You can try the Java Service Wrapper, which also support launchd on OS X. Furthermore run a Java application as Windows Service or on Linux using init.d/upstart.
http://wrapper.tanukisoftware.com/doc/english/launch-nix.html#boot
http://wrapper.tanukisoftware.com/doc/english/download.jsp
Please let me know if you have any further questions.
Best Regards,
Chrisitan
I would like to start a Eclipse RCP 3.x application from within Java code. I need to do this because I need to launch the RCP app from within a framework, that needs to be initialized first.
To have access to this other framework (which is SAP NetWeaver Mobile by the way), both applications need to run in the same JVM - therefore I can not call the .exe to start the RCP application. Within RCP I need to access the SAP framework.
Any help would be welcome.
Thanks in advance and best regards, alex
You can take a look at what the .exe does:
eclipse.c
Basically, it starts the VM with this jar: org.eclipse.equinox.launcher_xxx.jar and execute its org.eclipse.equinox.launcher.Main class
Look at the EclipseStarter class. I think you need to get the Equinox framework Jar file and have it be in your classpath to use this. That's called org.eclipse.osgi. If you have a situation where you are providing an API in your Java class to call into classes managed by Eclipses the situation gets considerably more complicated. Make a comment on this if that's the case and I can provide some information there.