How to Run jar file from JSP page
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.
Code :
<%
Process p=null;
try
{
Runtime runtime=Runtime.getRuntime();
p=runtime.exec("java -jar .\\src\\java\\Sphinx4\\Sphinx.jar .\\src\\java\\Sphinx4\\agmark_iitb.config.xml .\\src\\java\\Sphinx4\\agmark_iitb.batch");
Thread.sleep(19000);
}
catch(Exception e)
{
out.println("Error to run file!");
}
%>
But does not get run!!!
How can i run this jar file?
Thanks for your time.
Re: How to Run jar file from JSP page
a) Make sure the paths are correct b) capture the reference to the Process returned by Runtime exec, get the ErrorStream and InputStream, and read them to see if there is an error. c) For something that requires 19 seconds to run - not good practice to place this within a JSP file (making a client wait that long). If you are running sphinx to do search indexing, you might consider doing it as a cron job, or some other timed procedure which performs the indexing periodically
Re: How to Run jar file from JSP page
thanks,
plz have look at this post:
http://www.javaprogrammingforums.com...r-network.html
Actually i want to make above interface.
Any suggestion plz?
Re: How to Run jar file from JSP page
Sphinx is also the name of a well known search indexer - hence my recommendation above. If you have a long job to run, you might consider a) Using an applet b) Using javescript and AJAX c) Using java webstart - all of which would call a Servlet (or something similar) to do the long processing job of calling your application. This way you can notify a user of the delay through a progress dial or something similar. That being said, this doesn't really address your immediate concern in your post above - make sure the path is correct and try running the jar from within the web deployment directory of your server using the same command you pass to exec to be sure you can run it from that location
Re: How to Run jar file from JSP page
thanks,
ok i will try, and get back to you if any problem