• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Run jar file from JSP page

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
rubbery bacon. rubbery tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic