This question already has answers here:
How to schedule a java program to run daily in Windows?
(3 answers)
Closed 6 years ago.
I am designing a java application which needs to run at a specific time. My application is packaged in jar file and this jar should be activated every day at 3 AM in morning. My end Machine is windows machine not a server. Please help me out with this. Myapp.jar is the jar file and its located in D:/Collector/MyApplication/target/MyApp.jar is the location in my system.
Right now
java -jar MyApp.jar
is executing fine. But when my system goes off then again I have to initiate the same through command prompt. So I would also require a solution in which when system reboots the jar should be initiated.
How to schedule a java program to run daily in Windows?
This answer already is there but I don't want to do it with Task scheduler as it reduces my machine efficiency.
Windows has a "Task Scheduler", which is what you need to use to run a program on a recurring schedule and/or on machine startup.
You can program a task, or make an executable with your jar and place it on startup folder if windows 7 or lower
PROGRAM A TASK (SOURCE)
To Run Task Scheduler using the Windows interface
Click the Start button.
Click Control Panel .
Click System and Maintenance .
Click Administrative Tools .
Double-click Task Scheduler .
To Run Task Scheduler from the Command Line
Open a command prompt. (cmd or click Start, All Programs, Accessories, Command Prompt)
At the command prompt, type Taskschd.msc.
STARTUP FOLDER (SOURCE:)
On Windows 7 and earlier versions of Windows, the Start menu contained a “Startup” folder to make this easy. On these versions of Windows, you can simply open your Start menu, locate a shortcut to an application you want to start automatically, right-click it, and select Copy. Next, locate the Startup folder under All Apps in the Start menu, right-click it, and select Paste to paste a copy of that shortcut.
Create a bat file for that you want to achieve and schedule the windows Task Scheduler as listed below.
Click Start
Type Task and then click Task Scheduler
Once the Task Scheduler is open, you can create your own custom task by clicking Create Basic Task. This action starts a wizard that walks you through the process, prompting you with what program you want to execute, as well as how often and what time it should be run.
Related
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.
I have a Windows server which run several java .jar running in the background.
For example programABC.jar, programDEF.jar, and so on.
They were triggered trough the Windows task scheduler.
I can see through DOS command line tasklist or Windows "Task Manager" there are a couple of java.exe currently running, I can also tell their Process ID. But I don't know which instance belong to which jar program. How to identify these processes?
As a comparison in linux if we have the Process ID we can just cat /proc/YOURPID/maps that will give a clue what is the program name, run from where, etc.
Thanks in advance
In Task Manager processes tab click View|Select Columns. Scroll down the list then select "Command Line" then OK. You should see the command line of the process which should include the .jar file used.
I have a build java application for mac I want to run the application as root/superuser all the time when the application opened up. how would i go about to achieve this, I don't want to make a script that runs the jar or open terminal and type sudo to run the jar. I want it where if they double click on the runnable jar it will prompt the user requesting for root right.
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.
First, just wanted to thank everyone in advance for helping with this, let me take you on my journey...
Task: Run a Java application that is located in a folder on a file server using Windows Task Scheduler, simple enough.
The caveat, is that I would like to utilize the task scheduler option of "Run whether user is logged on or not." and this seems to be a tricky function...
I have set my account as the account that the task is to run under.
What have I tried?
Creating a task based on these actions:
Java.exe -jar "path to share jar"
Java.exe -jar "path to local jar"
Javaw.exe -jar "path to share jar"
Javaw.exe -jar "path to local jar"
All have had the same result with the "Run whether use is logged on or not." option : 0x1
Next, I tried creating a batch file to run this on my behalf and changed the task to run that batch file and I got all the same results. I have read that utilizing the "Start in (optional)" field of an action may solve the problem, but it did not.
After that, I created a .vbs file with code similar to the following:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0
Set WshShell = Nothing
This achieved a 'silent run', but task scheduler still did not run with the "Run whether use is logged on or not.", and ended in 0x1.
All of these work fine with the "Run only when user is logged on." option.
The reason I want to do it whether I am logged on or not, is because I want to run my application before I come in to work.
Update:
I've disocvered a few things. In power options for Windows, I had to enable the ability for scheduled tasks to wake the computer, felt kind of dumb about that one.
Using a simpler task - one that just creates a blank text file - this option works fine. I belive the problem lies with executing Java.
The task needs a user to run. It doesn't have to be the user that is logged in, of course, but a user is needed anyway.
Make a batch file (or equivalent) that works when you launch it manually
Schedule the same batch file (with cmd /c c:\full\path\to\batch.bat) to run as yourself, with your password and everything.
Now you are ready to debug your problem
The user Windows will use to run your task when no one is logged needs all the tools configured and working. For exemple, does local service have all the path and registry settings set ? Is the share readable by that user (the SYSTEM account does not have network credentials).
To help in debugging, use psexec. This command line will allow you to run your script under the SYSTEM account. Something like
psexec -dies cmd /c c:\full\path\to\batch.bat
+Welcome to SO !