I made a program in java that changes your windows wallpaper at a certain time of the day, this runs the UI and a thread in the background that checks if the wp should be changed or not.
I'm trying to figure out a way to keep track of that background thread and close it using a .bat file.
I run the program like this:
start javaw -jar wchanger.jar
And this is the solution I came up with:
taskkill /f /im "javaw.exe"
The problem with this is that closes every javaw process running on the pc.
I though I could name the process whatever I want, but that doesn't seem to be possible on windows.
Java.exe often crashes or is unresponsive when using the Filemaker Console.
We need to kill the process and start it again manually in order to make it work properly again.
I found that I can use the command taskkill /im java.exe /F to kill it, but I can't seem to start it again with the batch file.
I will change directory to Program Files\Java\jre1.8.0_91\bin\, then I will type java.exe, it shows me all the switches as if i type java.exe /?
But if I do a search in Windows, I see java.exe as being the result, and I click it with my mouse, it starts correctly..
How can I start java.exe correctly with the command line please
What are the correct switches to start java.exe from command line?
I can kill some applications in cmd using command taskkill /F /IM program_name.exe
But before killing any applications i want to save whatever the work has been done.
EX: kill the Microsoft word, but before that I want to save it. How can I do it through cmd?
Give me an idea. If it is not possible, even through Java also ok for me.
Thanks in advance.
Use this code to terminate the program in Java (in Windows):
try {
Runtime.getRuntime().exec("taskkill /IM word.exe");
} catch (RuntimeException e){
e.printStackTrace();
}
Be note that this can't even save data. Use java.awt.Robot mentioned by Elliott Frisch. (I hadn't use that before)
Taskkill without the /f asks the program to close, like you clicked File - Exit. Most programs will ask if you want to save the current file.
With /f it terminates the program without asking it. Nothing will be saved.
Remove /f from the command.
It feels like a dumb question to ask, but i cant seem to figure it out. when i run a *.jar file on windows it doesnt apears in the taskmanager processes. how can i terminate it , i have tried TASKKILL but it also doesnt work for me.
On Linux
ps -ef | grep java
It will show u a list of processes out of which one will be your executable jar. Just kill that process by its process id.
sudo kill -9 <pid>
Is there any way to do this from the java code of the same jar file. Like killing itself once process completed.
Find the process id by jps command & and kill them by taskkill command.
Note that "-f" is required with taskkill or it may just send a termination signal not actually terminating it.
You can identify the process in taskmanager by looking for "java" or "javaw" processes. The problem will be in case you are running more than one java processes. If you are able to identify your process, simply kill/end it.
Other way around:
Run
jps -lv
which shows PIDs and command lines of all running Java processes. Determine PID of the task you want to kill. Then use command:
taskkill /PID <pid>
to kill the your jar process.
Did you try to kill the java.exe processes in the taskmanager? It should stop then.
you could open jvisualvm to see the running java-processes. the process-id is displayed there. now open the task-manager go to the processes tab and add the process-id column to be displayed. now you can select the right java.exe or javaw.exe to kill
As everyone stated it is either java or javaw process. The problem is when you're running multiple apps like that. One workaround might be naming the process differently as stated in:
How can I set the process name for a Java-program?
spring boot start/stop sample (on Windows OS).
start.bat
#ECHO OFF
call run.bat start
stop.bat:
#ECHO OFF
call run.bat stop
run.bat
#ECHO OFF
IF "%1"=="start" (
ECHO start your app name
start "yourappname" java -jar -Dspring.profiles.active=prod yourappname-0.0.1.jar
) ELSE IF "%1"=="stop" (
ECHO stop your app name
TASKKILL /FI "WINDOWTITLE eq yourappname"
) ELSE (
ECHO please, use "run.bat start" or "run.bat stop"
)
pause
If you run the JAR file By command line and it is running yet. Press,
In Windows:
• Ctrl+C: shuts down the process, (it might be needed administrator privilege)
In Linux:
• Ctrl+ C : politely ask the process to shut down now.
• Ctrl+ \ : mercilessly kill the process that is currently in the foregroun.
In windows task manager you will see process called "java.exe". Kill that process your application will get stop.
To know the process first go to applications in task manager and then go to process by selecting that application. It will lead you to exact process of that application.
Regards,
Jaynil
if you are using a jframe and you want your application to stop when you click the "X":
here's a tutorial: http://tips4java.wordpress.com/2009/05/01/closing-an-application/
This is probably the easiest way to kill the process with no external dependencies (jps or anything).
wmic Path win32_process Where "CommandLine Like '%YourJarName.jar%'" Call Terminate
via How can we stop a running java process through Windows cmd?
I encountered a problem closing my javaw.exe process.
I like to do it in a soft way, so taskkill /F won't help.
Trying to close the javaw by taskkill /PID will end up in an "SUCESS" message, but the process still keeps running.
I'm using Windows XP SP 3 and got administrator rights on this machine.
Any ideas?
Thank you very much!
So, finally I found a solution for my problem, but is not solved using taskkill. There is a program written to send a CTRL-BREAK to any process called "SendSignal". I had tried this before, but all my process was responding had been an error-message and it kept running. I changed this program sending CTRL+C. After this I was able to shut my Javaw process gently. Thanks to all, for your help!
You can try:
taskkill /im javaw.exe