Batch Restart Java.exe - java

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?

Related

How to close java desktop application from .bat file

I have a java stand alone application. I build a jar, and I create a .exe file from this jar file.
Then I can start the application by double click on it. Now I need to create a .bat file to close the exe program. Now I build a .bat file like this:
TASKKILL /F /PID easyManagement.exe
pause
the script is executed without error but the program easyManagement is every time on.
EDIT
In task manager I can display my program like this:
This code:
TASKKILL /IM easyManagement.exe
run without error but the application is on every time.
You are using a wrong parameter for the taskkill command.
The /PID expects a pid and not the name of the program you want to stop.
Use TASKKILL /IM easyManagement.exe
or TASKKILL /F /IM easyManagement.exe to force the program to stop.
The /F might cause problems in the program you want to stop.
The keys Ctrl+C and Ctrl+Z will end the running of a batch file. Check out this link: Is there a way to write Ctrl-C in a batch file?

Keep info of new javaw process to close it later using cmd

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: How to stop a Executable jar which never terminates

I have a runnable jar which won't shutdown. i have executed it in my windows machine by double clicking on it. How can i terminate that application.
I dont what to kill all java.exe processes as i want other apps to run
There are three options:
Start in commandline with java -jar [YourJarPath] (Close by (Ctr + C) or close your commandline
Restart your Windows
Terminate it per TaskManager (Ctr+Alt+Del)
Under "Details"
Then look for "javaw.exe". Right Click and then something like Shutdown or exit Task.
To find the jar name, start in cmd (commandline) this code:
C:\Program Files\Java\[YOUR JAVA VERSION]\bin\jps.exe
it will return something like this:
The number befor the "name" is your PID that is also listed in the taskmanager right next to javaw.exe
jps -v
Will list all running jars along with their PID. Then you can just kill that process (with kill $PID)
JVM starts new java.exe process each time you run jar. Obviously because jar starting is performed as java -jar <jar_name>.
So by locating exact process which holds your jar's process you can safely kill without worrying about rest java apps.

creating a bat file which sends to background and closes (1 file)

im trying to do something simple, i want to start Burp Suite with extra java memory, but i don't want the CMD window to stay open.
If i don't use a .bat file and simple open cmd and type start /b "" java -jar -Xmx2g burpsuite_pro_v1.6.07.jar, Burp opens, the the process is sent to background, but the CMD window stays open. i can, however, close it manually and Burp will keep working.
when i try to put the thing into a CMD window, it will not even be sent to background, Burp stays dependent on the CMD, and i cant even add exit to the file.
i tried to solve the issue by following:
run bat file in background - this worked, but required me to have THREE files, i prefer a more elegant "1 file solution"
Just add the below line in your bat file and the java procees will run in background with no window open!
start javaw {Path of Your jar or Java file}
The following batch file commands should accomplish your purpose:
start "" /B java.exe -Xmx2g -jar burpsuite_pro_v1.6.07.jar
exit
You can probably even leave out the /B switch.
References
How can I run a program from a batch file without leaving the console open after the program start?
How to use the start command in a batch file?
Turns out the solution was simple: using javaw.
the issue was with using java.exe, some attempts even closed the CMD but opened a java.exe window (blank)
modding the file to contain:
start javaw -Xmx2g -jar burpsuite_pro_v1.6.07.jar solved it for me.

How To stop an Executed Jar file

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?

Categories

Resources