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.
Related
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.
I have 4-5 Instances of JAVA/JVM Running in Windows Server 2008 R2 Server, When I Open up Task Scheduler, I can see java.exe running, I am "not" able to find out the java instance details like what is the program? is it Tomcat? is it some Command Line etc?
From Task Manager , I could not get it? is there a way to find out from Command Line (or) Powershell?
In task manager, click View>Select Columns... and opt the command line column.
Open cmd and type following command, it will show all java processes:
jps -vlm
since you asked the powershell solution, you may use Get-Process java | select Processname, Path
Cheers,
GJ
It's %SystemRoot%\System32. The copy of java.exe is placed there during installation. You can also right click on the process and look up containing folder.
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 !
I am using Java code to install an EXE program on Win8, by executing this command "java -jar installapp.jar" in CML. The command line window is NOT opened by "Run as administrator", but the current user is a member of administrator group.
However, in the same CML window, if I install the EXE directly, it works. It just fails when the installation is executed by Java.
So anyone can give me a tip?
Thanks a lot,
Michael
To correctly install an application which includes writing to system-protected areas can't be done without elevating through UAC. That means the CML window must be Run as administrator.
Java executables are marked with manifest which requests asInvoker privileges. So the process would start with administrator tokens dropped if the parent process wasn't elevated. It's the whole point of UAC: even if you are member of Administrators group, you don't get the full, unlimited privileges until you elevate.
What do you mean by "install the exe directly"?
I added a value at:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
That looks like this:
Value Name: LDE
Value Data: "java -jar C:\LDE\lde.jar"
Really with the quotes (Because all the others where also with quotes). After adding this, I restarted my computer, but it didn't start automatically.
Will wrapping my jar in an exe help?
I'm running Windows 7.
Any help?
Thanks in advance.
Update:
When I remove the quotes, it works. But now there is appears also a terminal, which I don't need...
A couple of things to note here, concerning the two different issues in the problem:
Format of Windows Run keys
From the Microsoft Windows XP knowledge base:
Run keys cause programs to
automatically run each time that a
user logs on. The Windows XP registry
includes the following four Run keys:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
Each of these keys has a series of
values. The values allow multiple
entries to exist without overwriting
one another. The data value for a
value is a command line.
Note the emphasis on the last line. The moment quotes are used, the command is bound to fail execution in the same manner it fails as if executed from a command prompt.
Also, note that the above approach is for Windows XP and does hold good for Windows 7. More details can be found in this Microsoft Technet article on the options available in Windows 7.
The javaw vs java application launcher
Once the java process can be initialized at Windows startup, one will get a console window that continues to stay around until the process is terminated. This occurs if the java executable is utilized to initialize the application.
From the technotes of the java application launcher:
The javaw command is identical to
java, except that with javaw there is
no associated console window. Use
javaw when you don't want a command
prompt window to appear. The javaw
launcher will, however, display a
dialog box with error information if a
launch fails for some reason.
Therefore, if you wish to avoid opening a console window for the Java process, you ought to use the javaw executable.
This is very simple. You will find the startup folder in the C:/Documents and Settings/AllUsers/YourUserName/StartUp. It will be on similar kind of path just check it. Then just paste your jar file in that folder and it will work nice. Remember that you put the jar file in the startup folder of your user name folder. You may find that this folders might be hidden so just check it out. If you find this answer useful vote it. Enjoy.....