wood burning stoves*
The moose likes JSP and the fly likes Run jar file from JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Run jar file from JSP page" Watch "Run jar file from JSP page" New topic
Author

Run jar file from JSP page

Nikul Prajapati
Greenhorn

Joined: Sep 10, 2011
Posts: 7
HI

i want to run jar file from JSP page.

I have putted this jar file and related files on SRC directory of my webapplication.

and i tried this code in my jsp page.



But does not get run!!!
How can i run this jar file?
Thanks for your time.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41029
    
  43
It is considered bad design to do this kind of thing in a JSP page; you should move the code to a backing bean or a servlet.

Note that web apps do not have a concept of a default directory; you need to use absolute paths, both for files and -just to be safe- for the java command as well.

Lastly, be sure to follow all advice given in this article.


Ping & DNS - my free Android networking tools app
Nikul Prajapati
Greenhorn

Joined: Sep 10, 2011
Posts: 7


This is my web application example : webapplication
please have look at this application.

which absolute path should i use for Runtime.getRuntime.exec("java -jar Sphinx.jar agmark_iitb.config.xml agmark_iitb.batch");

Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41029
    
  43
That can't be determined by looking at it from the outside. If you don't know what it is by looking at the server directory structure, then you need to use the servlet context's getRealPath method.
Lei XianXiang
Greenhorn

Joined: Sep 09, 2011
Posts: 5
you should better not try to do it, because that a Web app is running in a Web container such as tomcat and it just run as a thread of the container. when the app is running, you should let the container to manage the app but not you to do it.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41029
    
  43
you should better not try to do it, because that a Web app is running in a Web container such as tomcat and it just run as a thread of the container. when the app is running, you should let the container to manage the app but not you to do it.

I'm not sure what you're trying to say - Runtime.exec start an OS-level process that runs outside of the servlet container. Where do you think servlet container threading comes into play?
Nikul Prajapati
Greenhorn

Joined: Sep 10, 2011
Posts: 7
main thing i want to implement.

I have one jar file which takes two files as arguments and gives one files as output.
I want to make one web interface that give two input files to jar file(which is on server) and get output file from server.

How i can do this?

Thanks for your time.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Run jar file from JSP page
 
Similar Threads
speech redirection from one app to other; changing input from mic to socket
Want to make java application available to all user of Network
Want to make java application available to all user of Network
running application in C on mobile phone with Android
problem with including jsapi library; sending SMS to server