Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to Run jar file from JSP page

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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.
        <%  
        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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default 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

  3. The Following User Says Thank You to copeg For This Useful Post:

    nicool (September 11th, 2011)

  4. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to Run jar file from JSP page

    thanks,
    plz have look at this post:
    Want to make java application available to all user of Network

    Actually i want to make above interface.
    Any suggestion plz?

  5. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default 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

  6. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to Run jar file from JSP page

    thanks,

    ok i will try, and get back to you if any problem
    Last edited by nicool; September 11th, 2011 at 02:50 PM.

Similar Threads

  1. Page one!
    By hal_v_1937 in forum Member Introductions
    Replies: 1
    Last Post: August 22nd, 2011, 09:31 PM
  2. reg how to use log in jsp page
    By javaking in forum JavaServer Pages: JSP & JSTL
    Replies: 7
    Last Post: April 9th, 2010, 12:36 AM
  3. Need help in JSP Page
    By vinothkumarrvk in forum Web Frameworks
    Replies: 1
    Last Post: March 12th, 2010, 06:43 AM
  4. Need help in JSP Page
    By vinothkumarrvk in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: March 9th, 2010, 04:20 AM
  5. Saving .jsp page as .pdf file while generating report for struts based web application
    By ravindra_kumar_tiwari in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: August 12th, 2008, 09:32 AM