How I can run Java application at system startup on Windows/Linux/MacOS?
Any implementation of JNA/JNI shall be welcome.
Take a look at http://wrapper.tanukisoftware.org. It provides a wrapper for java applications to run under the various operating systems. You can use the community edition.
You can consider your application as a service under linux, and add a script that could start it under /etc/init.d (on most distributions, I think). You'll then have to make the needed links to the runlevel folders, to decide when to run your application. I think you can use chkconfig too
A basic example of script can be found here
I don't have most clues for the other two systems, however.
On windows you can use reg add
Add the path of your application to hklm/software/microsoft/windows/current version/run
To see more ,on command prompt type reg add /?
Alternatively yo can use system call to add it from your application itself
Take a look at http://yajsw.sourceforge.net/.
It's free and compatible reimplementation of TanukiSoftware Java Service Wrapper featuring free 64-bit support.
There is also a comparison table for YAJSW, JSW, ACD and L4J.
Related
I am using Elasticsearch which uses Java 8. I also want to install kafka on the same machine but kafka uses java 11. Both services are to be run in parallel. Can anyone tell how can I run both java versions at same time?
Manually download and unpack Java
https://adoptium.net/releases.html?variant=openjdk11
https://www.azul.com/downloads/?version=java-17-lts&os=windows&architecture=x86-64-bit&package=jre
Instead of simply starting java with the
java -args commandline,
you can start it via /install/path/to/java/bin/java -args
or, for windows, use C:\install\location\bin\java.exe -args
You might want to make some start scripts / batch files for that, depending on the exact requirements of your system and Elasticsearch and kafka and possibly other software.
That's it.
one little addition:
If you can NOT directly call java, or the software starts more java apps via the 'default' java, you can also use scripts to manipulate the PATH variables of your system before starting the app. Then you (and your apps) can simply call java -args again.
Once you download different versions of JRE(java runtime environment) to your local, if you use Eclipse IDE, you can checkout different projects in single workspace & specify Java Build Path with JRE version you want.
This way, you can run multiple applications having different versions of Java.
I think other java IDEs also have this kind of support.
I have a console application (written in Java), which should run on a Linux machine until it is stopped.
Logging is done by the application itself.
The application needs to be stopped whenever a new version is available (i. e. I login, stop the application, copy the new JAR file, and then launch it again).
What are the options for implementing this, apart from those specified below?
Known ways to do it:
1) Tanuki service wrapper
2) nohup java -jar myapp-1.32.jar &
I use Java Service Wrapper, but you already mentioned it. I think it should suit your needs.
Apache Commons Daemon is also popular: http://commons.apache.org/daemon/, but I never used it.
I'm using this startup script: http://shrubbery.homeip.net/c/display/W/Java+Daemon+Startup+Script
[Changed domain name - by wiki owner]
Some modern Linux distributions have switched to upstart. That's a daeomon starting and stopping all the other services. I'd definitely look into that. Since it solves some tricky problems with production ready start scripts. The downside is that it has no java specific functionality.
There also the apache commons deamons http://commons.apache.org/proper/commons-daemon/jsvc.html
Jsvc is a set of libraries and applications for making Java applications run on UNIX more easily.
Jsvc allows the application (e.g. Tomcat) to perform some privileged operations as root (e.g. bind to a port < 1024), and then switch identity to a non-privileged user.
I have to make a tool for automated distribution of the Java code. Basically, I have a repository with compiled files, and about 50 locations to distribute the same code.
Does anyone know some opensource tool which can help me in this process?
If you are speaking about easy deployment of java applications, use JNLP. The only thing user has to do in this case is to surf to URL.
If you wish to do it without any user participation I believe the solution depends on target platform:
Use SSH for Unix platforms
WNI or telnet for windows platforms.
To make the solution more portable you can run
wget THE-JNLP-URL
on target machine using SSH for unix like platforms.
I do not know built-in command like wget for windows. But you can implement this in VBS or JS and then invoke the script using cscript over WMI or telnet.
Good luck.
Either you can distribute it out with rsync, or you can use Java WebStart to let the user JVM download and invoke the software as needed. For Windows based clients this is usually the easiest, especially when you want people to update to a newer version.
I have created a desktop application in Java using NetBeans 6.1 and made a jar file of the application. Now I want to make it automatically start up whenever a client's machine boots up.
How do I do that?
There are many commercial installers which can do this
http://www.advancedinstaller.com/jre-install.html
Are you looking for a free/OS one?
Thanks
Krishna
This installer can create a file with "msi" extension that will behave as regular windows installer. It bundles your jar file and JRE together into single file. The program acts as a "wizard", where you configure all necessary options.
Take a look at this product:Advanced Installer
Good luck.
If you simply want to have a java application autostarted in Windows you could just create a link in the users autostart folder calling javaw the same way you'd normally call java.
This is just meant FYI, the other suggestions are more general, of course, but this could be the simplest solution...
҉ works
I have found the following order best suite to take a decision for commercial or free one, to fit your needs (most of the following does auto startup + extra features):
Order show more features on top:
BitRock: see features
i would really use this one, because it does all cross platform + Jnlp + Prerequisite
Tanukio: enter link description here
IzPack
Advancedinstaller: features
(optional) Jnlp web start: example (this should become future way of installing)
Please note that, prerequisite is not mentioned, most of there feature list, which is very important to have in all of them, because many case we use third party libraries/dependencies, so the best question would be to know if they support it or not.
Take a look at Tanuki's Java Service Wrapper. The Community version does what you need, plus a lot more.
If you only need to run a Java program periodically, I like pycron, which installs itself as a Windows service and then reads a Unix style crontab file where you would enter a line that tells pycron when it needs to run the java process (eg, every night at 3am).
I am looking for the best method to run a Java Application as a *NIX daemon or a Windows Service. I've looked in to the Java Service Wrapper, the Apache Commons project 'jsvc', and the Apache Commons project 'procrun'. So far, the Java Service Wrapper looks like it's the best option... but, I'm wondering if there are any other "Open Source friendly" licensed products out there.
I've had great success with Java Service Wrapper myself. I haven't looked at the others, but the major strengths of ServiceWrapper are:
Great x-platform support - I've used it on Windows and Linux, and found it easy on both
Solid Documentation - The docs are clear and to the point, with great examples
Deep per-platform support - There are some unique features in the window service management system that are supported perfectly by service wrapper (w/o restarting). And on Windows, you will even see your app name in the process list instead of just "java.exe".
Standards Compliant - Unlike many ad-hoc Java init scripts, the scripts for service wrapper tend to be compliant with LSB standards. This can end up being very important if you ever want high availability management from something like Linux Heartbeat/HA.
Anyway, just my 2 cents... :)
Another option is WinRun4J. This is windows only but has some useful features:
32 bit and 64 bit support
API to access the event log and registry
Can register service to be dependent on other services (i.e serviceA and serviceB must startup before serviceC)
Its also open source friendly (CPL) so no restrictions on use.
(full disclosure: I work on this project).
Are there any special attributes that you need to apply (like OS guided resource management) that you need to support? Otherwise, for Unix you should be able to daemonize your application by writing an appropriate init.d script and setting your app to start automatically.