0

I try to execute a java swing jar with a JFrame from a webapp like this :

Process p = Runtime.getRuntime().exec("java -jar my_swing_app.jar");

My app starts (logs are ok) but my jframe doesn't appear. When I run the swing app with powershell, there is no problem.

I try to execute this jar in a java web application that runs in Wildfly server.

Any idea ? Thx.

UPDATE

I tried with another command (without java swing app) :

Process p = Runtime.getRuntime().exec("cmd /c start C:\\test\\build.bat");

The result is the same. I can see the process on the windows process list (build.bat) but the command prompt doesn't appear.

bart
  • 33
  • 1
  • 1
  • 8
  • 6
    You're trying to run a desktop app from within a web server, I assume you're expecting it to appear on the client computer? It's probably appearing on the server's computer – MadProgrammer Oct 14 '15 at 09:21
  • I forgot to mention that the web server and client are in the same computer – bart Oct 14 '15 at 09:28
  • I think you need an applet embedded in html instead –  Oct 14 '15 at 09:30
  • You may want to look at [this stack overflow question](http://stackoverflow.com/questions/14979140/swing-application-on-web-browser), it may provide a direction to solve your problem. – aaroncarsonart Oct 14 '15 at 09:30
  • My swing application is used to update my webapp (stop wildfly, reload war etc ...). So , I think, I need an external app. – bart Oct 14 '15 at 09:40
  • You web server might be in headless mode, although I'd expect it to throw an `Exception` then – MadProgrammer Oct 14 '15 at 10:21
  • No exception in Wildfly logs. What do you mean when you said "headless mode" . – bart Oct 14 '15 at 12:27
  • It is highly likely that WildFly has started with the `-Djava.awt.headless=true` property set. This means that the JVM won't run any graphical components. – Mike Oct 14 '15 at 12:38
  • Why do you want to use WildFly for this in the first place? A Java EE application server isn't really built for this sort of thing. – Mike Oct 14 '15 at 12:40
  • I have a web app that is running on Wildfly. Sometimes, users can update this application (a new version is available). To do that, I need to execute tasks like download new version, deploy new war, restart server etc... So, I have an exteral standalone jar that I need to execute (with java swing for progress bar, update logs etc..) – bart Oct 14 '15 at 12:47
  • I add "-Djava.awt.headless=true" to wildfly java_opts and it works. Thanks to MadProgrammer and Mike ! – bart Oct 14 '15 at 13:34

1 Answers1

0

The problem is the 'java -jar my_swing_app.jar' is getting interpreted as a single command. Instead try

            String[]cmd={nativeConverterCommand,tmpHtmlFilePath,tmpPDFFilePath};
        Process wkhtmltopdf=Runtime.getRuntime().exec(cmd);

Refer javadoc

The first string is the command, the 2nd and third arguments.

Ironluca
  • 3,402
  • 4
  • 25
  • 32
  • Thanks but the command semms to work well. Indeed, I can see java process in the process list (same result with the string array). – bart Oct 14 '15 at 12:27