I have an application which starts second spring boot application (which contains some Swing GUI) from java code using following code
String cmd = "java -jar file.jar";
Process process = Runtime.getRuntime().exec(cmd);
but when program executes this command, I can see the application starts in the task manager and it's GUI is visible. The weird thing is when I close the second application(using JFrame Exit feature) it does not get closed and it hangs until the first application is running.
The main problem is my second application is bound to my first application and it hangs until I closed the first application.
does anyone know how do I resolve this issue ?
Related
I have very strange problem- from one program I run another application- by Runtime.getRuntime().exec(). It's look like something like this:
Runtime.getRuntime().exec(java -jar Something.jar + "bla bla params");
And when I run this code from new project- everything is ok. But if I run this app from our system in company- the smaller application occasionally hangs.
And there is even better- if I close "parent" program, application "return to live"!
The app (which hangs) is small java swing application. The big application is java swing app too.
It uses the same db connection as application which run small app (Something.jar). Maybe that cause problem?
But for me it have no sense- if I run app by Runtime.getRuntime().exec- the running app is separate application container in separate JVM!
How test/debug that configuration?
I'm trying to get my Java application to be able to restart itself programmatically.
I already have a working solution for when it's executed as a standalone application - the application invokes java.exe with its own classpath, jvm parameters, class name, and command line arguments; and then it exits (see my stack overflow answer).
But this approach doesn't work cleanly when the application is run as a windows service - instead of a restarted service, I end up with a java.exe process executed by the SYSTEM account, and the state of the service is stopped (since it exited). So the application does restart, but is no longer a service.
I know that windows restarts services that exit with a non-zero exit code but a) I'm not sure that it always works (see this question) b) I'm not sure how to identify the fact that the application is running as a windows service in the first place - System.getProperty("user.name") just seemed to return the hostname followed by a dollar sign ($) in my tests.
Can anyone suggest a solution?
The Launch4j package has a <restartOnCrash> parameter for services.
I'm trying to make an web service which can also get commands via shell. So I want to make this app work like a daemon. So my question is how can I get arguments passed to shell while web service runs in the background? I can make script which starts this app as a daemon and give it a name but how can i get arguments in java passed later on?
EX. mydaemon add -stream somepage.com -channel channelName -start 2014-09-19 20:00:00 -end 2014-09-19 20:45:00
I can start a new thread in main method which gets system.in but will this get stuff sent to PID of my app. Btw, if this can make a change - I'm using Spring Boot in my app.
There are many Q & A on Runtime.exec, but still I found a strange behavior. I am running desktop application in which jobs (a kind of javax.resource.spi.work.Work) are submitted and executed in JBoss application server. Following is the code to run some script, which is blocking whenever it needs to launch any GUI. For example, if the script or command is
start notepad
The GUI is not launched, but i can see the notepad.exe in Task Manager. I dont know what is blocking to launch the notepad GUI. Following is the code:
String pathString= "D:\\folder\\abcd.bat";
pro = runtime.exec(new String[] {
pathString
});
Content of abcd.bat file is
start notepad
No error logs or exception found. The above code works very well in normal Java class.
EDIT: Issue found only with .exe files which launch GUI. Some .exe which does not require launching GUI but running some background task is executed very well with my code.
EDIT: Forgot to say that my application is running as service.
Starting from Windows vista, services not allowed interacting with desktop. More details here . It is windows security restriction to not allow services to interact with desktop. I have done changes in regedit and Log On properties of my service, it worked well.
I have been working on a Web Application for Intranet use only. I work with Apache 7 and Windows Server 2003.
In one of my page, I need to open an external application that we can locate in C:/Program Files/etc... with some parameters already initialized. Of course, the user has to use the web application on the server to make it work (that will be the case).
To open the application, I use the ProcessBuilder object.
The problem:
When I work locally with Eclipse and run the server by hand, it works perfectly. Any application can open itself from a web page.
But when I use the tomcat windows service (and that's what we want to use on the server), it just never launches. Or to be more specific, it launches and stops the application directly. No java errors thrown and process.waitFor() with an exit value of 0. The fact is that we can run processes via the web application (I tried to run simple batch files), but when there is an UI involved, it will never appear.
Again, on the server this time, if I launch tomcat7.exe (that we can find in the %CATALINA_HOME%/bin directory) with a double click or cmd, the UI in the web application will appear. If I launch it with services.msc or tomcat7w.exe or tomcat7 start via cmd, it will not.
I thought of several things:
use another user to start the service
change the way the service is launched (StartMode: jvm, java. I did not succeed with exe)
I read Tomcat 7 Windows Service How-To many times but didn't find out anything to solve my issue.
Have you any idea of what is happening, and how to solve this issue ?
What is the big difference between running tomcat as a service and from the command line?
Option 1
If you open your service's properties window, go to the Log On tab then check the "Allow service to interact with desktop" check box you will get the behavior you want. Also depending on what app you what to run you may need to change the log on account.
see Launching GUI App from Windows Service - Window Does Not Appear
Option 2
Did you try start a cmd and there use
start /c "c:\path to\exe"
in cmd.exe type
help start
Option 3
You will need a daemon service that is not run as a service. windows puts certain restrictions on service apps.
This sleeping app can be started by tomcat or other your self. it can listen on a port or poll a folder for a new file, and when it gets a job to do it starts the app you want. Via port or text file you can send the parameters.