This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run jar file from JSP page

 
Nikul Prajapati
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nikul Prajapati
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Rancher
Posts: 42968
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic