Automatically running a Java application at OS startup - java

I need some way of starting my Java application without forcing the user to run the application manually. I'm not entirely sure how I would do it, can anyone provide any assistance?

Run it as a Windows Service. It's the way to go.
For various ways to run it as a service, check out the answers to the following questions:
Install java program as a windows service: Alternative to JavaService?
How to create a windows service from java app
You can also read this article.

use registry editor to add path of .exe file to startup goto Run from start menu, type regedit.exe
then navigate to HKEY_CURRENT_USER / SOFTWARE / MICROSOFT / WINDOWS / CURRENT_VERSION / RUN
on the right side, create a new string value with
name = "anything" and
value = java.exe -jar "complete path of the file"
press ok to save the registry entry, restart your pc to see effect

Related

How can I host my Springboot application in my own computer like a background service?

I want to host my springboot application on my on PC, I want it to start with the computer, just like databases do. But I can't find anything related (probably because I am asking the 'wrong' way). There is any way to start the springboot application with my pc in the background, with no CMD showing or having to keep intelijj open?
I tried to search how to host the application, but didn't found any thing 'locally' based, everything was how to host in X cloud or Y domain/host. What I want is to my application run on the background of my PC so I can use it as a personal system, but don't want to keep a cmd open or intelijj
Also I can't really use docker.. that was the way I was trying before, but I can't let Hyper-v active..
There are 2 steps:
Get command line of execution of your application runned by IntelliJ. To do so:
You have to create a file with extension ".bat" (batch file) with the contents of the command copied above, than follow the steps bellow to define it to run in the startup configuration of the windows 10:
Run a batch file at loading of Windows 8 and 10 Once the shortcut is created, right-click the shortcut file and select Cut. Press Start, type Run, and press Enter . In the Run window, type shell:startup to open the Startup folder.

How Can I Use a Java Application Instead of Desktop?

I want to make a Java Application that will start automatically when I start the computer and will run instead of the desktop, so the desktop-terminal etc will be unreachable for users. The users must use nothing but the application and when they close the application, the computer also must be turned off automatically. How can I do such a thing for a simple Java Application (jar)?
Shortly, for ubuntu you have to:
Remove desktop environment, just look around for some guides, it depends by which desktop you have (GNOME, XFCE, KDE, etc). https://askubuntu.com/a/147870
Add a script in /etc/rc.d and link it in rcS.d https://unix.stackexchange.com/a/83752.The script have to run your application, wait for end and shutdown,
an example could be:
#!/bin/bash
nohup java -jar MyApp.jar &
wait
/sbin/shutdown -r now
Try this in a virtual machine that you can reach in SSH or in some other ways, after you removed desktop environment, you cannot open a terminal.

Java autoconfigure startup execution at first launch

I'm trying to program something that, at first execution, in any OS could, set itself at startup OS programs list.
There are any library that do that? Or I should search how to do that in each OS?
I want to do an unique file, so I don't want to use scripts and anything.
For the moment I don't found any API for solve that.
In Unix system modifying (I think it could work in MAC, but not verified)
~/.profile <- User Privileges
/etc/profile <- With admin privileges
For Windows you can modify directly the key register
Run Java application at Windows startup
Or try to copy the program to the startup folder

Wrapping a jar file in a Windows service

Have you had experience with running a jar file using a command line, wrapped in a Windows service?
I'm trying to find a way to run a jar file without being logged into the machine, and since it allows command shell, I was wondering if it's a good idea.
Thanks!
Original Post:
I'm trying to run Associated Press's Web Feeds Manager, which is basically a jar file that can be run when logged in by double clicking it.
I'd like to run the same file but without being logged in to the machine. In their manual (http://wfm.ap.org/admin/content/help/Running_Agent_on_a_Remote_Server.htm) they write how to do that, using a commandline parameter.
Basically I'd like the jar to run as a Windows service, regardless of who's logged in, but Googling it showed it was problematic.
Have you had experience with remotely running jar files? What are the pitfalls?
Thanks!
On a google search, I came across this article -
Running Jar Applications as a Windows Service
It mentions about open source Java Service Wrapper project from Tanukisoftware.org for accomplishing this task.
Note: I've not used this personally.
If you are not interested in having the service started/stopped at boot/shutdown, but you just want the program to be started manually and keep running after logout, here is what you do:
$ nohup java -jar foobar.jar > foobar.log 2>&1 &
which means: start my foobar.jar (java -jar) and keep it running after I logout (nohup) redirect stdout to foobar.log (>) and also the stderr (2>&1), and make it running in background (& at the end).
Instead, if you are interested in installing a "service" in your linux box, there are many options, depending on what distribution you are using.
The most common are upstart (for ubuntu) and System V init scripts (Redhat or others). Also cron can be used to start/stop services at startup/shutdown.
You can find an example of installing a java app (hudson) on an init system here, or doing the same thing with upstart. Or, as I said, cron could be an option.
On Windows, there is Java Service Wrapper. And not much more.
For windows Java Service Wrapper is a better choice
My favourite is the upstart on linux, but it is Ubuntu only.
On Windows I see many alternatives according to this forum.

Java start program on user login (platform-wide)

Across linux, MAC, and Windows, is there any way to make a Java program startup on login? I know on windows their would just need to be a shortcut to the jar file in the user's startup folder. But for linux and MAC what should i do?
There's no cross-platform method of starting a program at login or boot, but you can configure each individually.
Windows - Put the program in your user's startup folder in or use a scheduled task, both detailed here: [Instructions]
Mac - Configure through system preferences: [Instructions]
Linux - Configure ~/.bashrc to start on login or use /etc/rc.d/rc.sysinit to start on boot.

Categories