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
Related
I would like to monitor a local Java application using JVisualVM. When I'm starting it, the popup 'Local java application cannot be monitored' or 'Local Applications Cannot Be Detected' is shown. I have read here that it is a permissions problem. Every time when I grant full access to folder %TMP%hsperfdata_MY_USER_ID to me (logged user) and everyone (windows user), the permissions are reset when I start JVisualVM.
I know that another solution is to delete hsperfdata_MY_USER_ID, but why does the permissions trick not work? Is the permissions folder reset a Windows feature?
System : Windows 7
Tested on cmd started as administrator. I use the same accounts and I do not pass any JVM parameters such as com.sun.management.jmxremote.port=XXXX.
For people stumbling here who have a FAT-type file system:
Make a directory (e.g. e:\temp) on an NTFS disk.
Start both java and jvisualvm with an environment variable TMP=E:\temp.
There are three options to set the environment variable for java:
In your IDE, go to the project options or launch options and find the 'Environment' entry, then enter TMP=E:\temp
Open a cmd prompt, and execute set TMP=E:\temp before launching youur java application from the same prompt.
Put the two lines you'd enter at the cmd prompt in a .bat file. Optinally add pause at the end of the bat file to prevent the console window from disappearing in case of a runtime exception or vm crash.
Similarly, for JVisualVM, use one of the last two options.
I had the 'Local Applications Cannot Be Monitored' problem, got it solved like this:
Exit all java processes
Delete existing folder %TMP%\hsperfdata_username
Start jvisualvm, which created the folder with a different casing: %TMP%\hsperfdata_USERNAME
My problem and solution have nothing to do with permissions, so may not work for the original problem in the question.
Also see https://visualvm.github.io/troubleshooting.html#jpswin
This answer is a bit trivial but might still save time.
Check your java application is not lauched with the "-XX:-UsePerfData" option.
My username: A4000000
I had to delete C:\Users\A4000000\AppData\Local\Temp\hsperfdata_a4000000
AppData is a hidden folder.
Then once starting VisualVM again, it created the following:
C:\Users\A4000000\AppData\Local\Temp\hsperfdata_A4000000
Notice the case difference.
Then start:
C:\visualvm_213\bin> visualvm.exe --jdkhome "C:\Program Files\Java\jdk1.8.0_202" --userdir "C:\Temp\visualvm_userdir"
I need to write a program which executes
whenever some one logged In to the windows system.
It is for daily report generation purpose.
I have written the program but couldn't get how to execute it on user login.
All the help would really be appreciated.
EDIT most of the people suggesting that I should put file in startup folder, but startup files only execute if 'system started/restarted'... I need to run the program whenever a user login like if the computer is started but locked and then someone unlocks, this program should be executed.
Correct me if I am wrong.
If you are working on a Windows OS then you can create an executable jar file of your java.
In order to make it launch at login you need to include it to the windows startup list.
You can create a batch file (.bat) in which you put:
"<YOUR PATH TO JAVA>/javaw" -jar "YourJar.jar"
Add this .bat file to windows startup check this
Batch/CMD: Adding files to Startup list
Hope it helps !
Setup your java application to run as a windows service.I think this answer will help you.
Answer is here
Create a batch program and put it on startup that should start your target file to run what you want to do.....
batch code :
start java target.java
Must setup the path for startup b4 run....
#happy Dev: hope you already know how to make a .bat in windows, just create a bat file which has line to execute java. or for more help on this you can see:
http://introcs.cs.princeton.edu/java/15inout/windows-cmd.html
Just make sure you have java installed on that machine. and your environment variable is set for java other wise you have to provide the complete java bin path.
Regarding how to run on login. simple way to go:
for windows 7: start menu--> All programs--> find a folder name startup and right click on it. there you can see open for all users open it and place your file there. every time when some user login the bat file will be executed automatically. and remember this wont work on hibernate. or to open that location you can just go to:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
for Other OS path is almost similar with just a minor difference.
You can use Task Scheduler for Windows Platform and configure which file to call at Login Time.
C:\Windows\system32\taskschd is the location.
Create a basic Task or Create Task...... are the options.!!
You can schedule the time of your task to get executed.
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
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.
I have a Java application that needs to implement installation features of making a JAR launch on startup.
I can do this on Window by entering a REG file into the registry, but how can I do this on UNIX platforms? Linux and Mac if the methods are different.
Do Linux and Mac have system startup folders?
Remember that I need to do this programmatically not through system preferences or anything like that.
On Linux, the classic way would be through adding a script in the appropriate /etc/rcN.d/ directory (where N is a number 0-6 representing the 'run level'). I'm not sure whether that's still the recommended way, but it usually is still supported. This would also work with minor variations for other mainstream Unix variants (Solaris, HP-UX, AIX).
On Mac, you have to work harder. The files /etc/rc.common, /etc/rc.imaging and /etc/rc.netboot are related, but there are no /etc/rcN.d directories. There's also a script rc and another rc.local. Typing man rc reveals:
DESCRIPTION
rc.local is now unsupported and has been replaced with launchd(8), which bootstraps itself via the launchctl(1) bootstrap subcommand to read in launchd(8) jobs from the standard locations.
SEE ALSO
launchd(8), launchctl(1)
So, you should investigate launchctl and launchd, particularly launchctl.
This is how I would do it on ubuntu.
First create a bash script to run the java app, similar to.
#!/bin/bash
java -jar "helloworld.jar"
and save it, in this case called 'HELLOWORLD' in /etc/init.d.
Need to make the script executable so need to run
chmod +x HELLOWORLD
Finally to make it run on start up
update-rc.d HELLOWORLD defaults
On Macs I think its launchd, and on linux its init.d. They are config files.