Start java application from jsp?

is there any way i can have a JSP, bean or servlet start a java application on the server? maybe a better question is: what can i do to make sure that some class is always running on my javaserver? im talking about the server app. for a chat program that im making that will be an applet in a JSP page along with a load of other JSP pages that do other things...
sorry for my incoherence. i usually talk better than this. :)
Laz

just replying so the message comes to the top of the forum... can anyone help me here?
Thanks
Laz

Similar Messages

  • Starting Java application from other Java application..

    Hi all,
    I was wondering if it is possible to start a Java program from an other Java program.
    In Java program 1, I have this code to execute the other application:
    try {
        Process p = Runtime.getRuntime().exec("cmd /c java -cp JavaApp2.jar com.test.TestFrame");
    } catch (IOException e) {
    }I tried this code, but unfortunately I couldn't opened the other (JavaApp2.jar) Java Application. Is there a way to open the other application anyways?
    I really hope someone can help me. Help would be greatly appreciated! Thanks in advance.
    Tongue78.

    What if there is no JAR file?Then you can make it out of the .class files. And to anticipate your next question, if there are no .class files there is no application at all, so you can't exec() it or call the main() method directly. Your point?
    And JAR isn't part of the Java language.It is a major part of the Java platform.
    This means you can only get access to a JAR file via the OS. Wrong again. CLASSPATH. URLClassLoader.
    In short you cannot just shout main() in a Java program and hope some other Java program will hear you and start.Absolute rubbish. If the required classes are on the CLASSPATH you just call com.company2.app2.main(args) and off you go. Or you can load the main class and invoke its main() reflectively.
    No source code required, or 'source code merge' either.

  • Start java application from java program

    My problem is the following:
    I start a java application A that allows you to select a couple of .java files.
    After having choosen them, the application adds some additional information to these .java files (that means some more lines of code � we call it �infecting� the java files).
    After the files have been infected, I want to start the application B implemented by these choosen and infected .java-files (without a new start of the Java Virtual Machine)
    For doing so, we use the following method whichs works quite fine:
    public static void ExecuteWithInvoke(String path, String classname)
         try
              new URLClassLoader(new URL[] {new File(path).toURL()})
                   .loadClass(classname).getMethod("main",
                   new Class[] { String[].class }).invoke(null,
                   new Object[] { new String[] {} });
         catch (Exception e)
         {e.printStackTrace();}
    The only problem that occurs:
    When the application B is launched, the �old� version of the choosen .java files is used and not the current, already infected version of these files. (I guess because the �old� .class files are used.)
    I solved this problem by finishing the program A after the infecting and restart my application B manually. In this case the infected .java files are used (I guess the new Start of the Java Virtual Machine solves my problem by reloading the �new� .class files)
    How can I reach to start my application with the mentioned method but with the infected .java files and without having a new start of the JVM ??
    Can anybody help me?
    Thanks in advance
    Sorry for my English, it�s a long time since I quit school

    Hello,
    my problem of reloading classes is still unsolved although you tried to help me!
    Therefore I posted a little program to illustrate our difficulty.
    It would be nice if somebody could have a look at this program.
    We have a file Testdatei.java whose only method is the main method.
    I get the class object of this file and with the help of Reflection the declared methods.
    Evereything works fine so far.
    Then I change the content of this file by adding an additional method a() (see change() for this).
    Now I delete the old class file and I compile Testdatei.java again (see compileJava()) and once more I get the class object for this changed file. Afterwards I get the declared methods for this class via reflection.
    But instead of showing now the methods main() and a() Reflection still only shows the method main().
    I guess the changed class has not been reloaded!!
    package testpackage;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.lang.reflect.Method;
    import java.net.URL;
    import java.net.URLClassLoader;
    import com.sun.tools.javac.Main;
    public class LoadClass
         private File f;
         private Class c = null;
         private Object o;
         public LoadClass()
              f = new File("C:/AAJ/src/testpackage/Testdatei.java");
              try
                   o = neuesExemplar(f.getPath(), "testpackage.Testdatei");
                   c = o.getClass();
                   System.out.println("Class " + c.getName() + " found.");
              catch (Exception e)
              {e.printStackTrace();}
              Method [] method = c.getDeclaredMethods();
              for (int i=0; i<method.length; i++)
                   System.out.println(method.getName());
              change();          
              compileJava(f.getPath());
              File fileToDelete = new File("bin/testpackage/Testdatei.class");
              System.out.println(fileToDelete.delete());
              Class cla = null;
              try
                   Object o = neuesExemplar(f.getPath(), "testpackage.Testdatei");
                   cla = o.getClass();
                   System.out.println("Class " + cla.getName() + " found.");
              catch (Exception e)
              {e.printStackTrace();}
              Method [] methods = cla.getDeclaredMethods();
              for (int i=0; i<methods.length; i++)
                   System.out.println(methods[i].getName());
         private int compileJava(String javaFile)
         String[] args = {"-d", "C:/AAJ/bin/", "-classpath", System.getProperty("java.class.path"), javaFile};
         return Main.compile(args);
         public static void main(String[] args)
              new LoadClass();
         private Object neuesExemplar(String pfad, String klassename) throws Exception
         URL url = new File(pfad).toURL();
         URLClassLoader cl = new URLClassLoader( new URL[]{ url });
         Class c = cl.loadClass(klassename);
         return c.newInstance();
         private void change()
              FileWriter fw;
              BufferedWriter bw;
              try
                   fw = new FileWriter(f);
                   bw = new BufferedWriter(fw);               
                   bw.write("package testpackage;");
                   bw.newLine();
                   bw.newLine();
                   bw.write("public class Testdatei");
                   bw.newLine();
                   bw.write("{");
                   bw.newLine();
                   bw.write("public static void main (String [] args)");
                   bw.newLine();
                   bw.write("{");
                   bw.write("System.out.println(4);");
                   bw.newLine();
                   bw.write("}");
                   bw.newLine();
                   bw.newLine();
                   bw.write("private void a ()");
                   bw.newLine();
                   bw.write("{");
                   bw.newLine();
                   bw.write("System.out.println(55);");
                   bw.newLine();
                   bw.write("}");
                   bw.newLine();
                   bw.write("}");
                   bw.close();
                   fw.close();               
              catch (IOException e)
              {e.printStackTrace();}                                             
    I�m using eclipse 3.1.0. Is it possible that it�s a bug in eclipse that eclipse holds the old class file in memory from the beginning and always refers to this one and not to the new compiled one?
    Thanks a lot
    Simon

  • Calling java application from jsp using onUnload

    I have tried to find the answer to this by searching many jsp, js and java forums, but have not had much luck. I hope someone here can help out. I have written a jsp page that passes a sql string to a java application when it loads. That application creates an xml file (a report) and returns the filename, which is the target of an onclick event. What I want to do, is to delete the file when the page unloads. I have written a separate application that will delete the file, but onclick and onunload events apparently only take JavaScript commands. I have tried to embed the jsp code into an onunload event, but it runs when the page is originally loaded. In addition, I created a separate jsp page that deletes the file, and I call that page onunload using window.open(). I can set that page to self.close(), but I can't get the page to not show itself. Even if I set the height and width to 0 (or 1), it seems to appear 100X100. Can anyone give me any suggestions on what to do in this situation? Thanks.

    When my jsp page loads, I create the file using this code:
    String filename = printtasktest.createxml(closed,encodedSQLString);
    printtasktest is a java application on the server, that
    creates a file on the server, and passes the filename back to the jsp page. Later I use this filename as a target of an onclick event:
    <div class="button" onclick="printTask('<%=filename%>')">Print This Page</div>
    printTask() is a javascript function that opens the printable page using window.print() and self.close().
    The problem I have is that the file hangs around after, and I want to delete it when the user leaves the page.

  • Start java application from another programm

    Hi everyboda on this side,
    i got a big problem. I would like to start out of MS excel an java programm and I would like to hand over data from the MSexcel programm to the java programm. I hope someone can help me. My idea was to create a batchfile, which I start from the excel-programm to run the java programm, but how do I hand over the data from excel to java?
    In advance thanks to all the ones, who tried to help me - max

    You could try to use a JDBC-ODBC bridge that allows you read the data of your excel file.....
    Here, a guide for use it:
    http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html
    Hope this helps.

  • How do I start and suspend Java Application from say C++ program

    I want to start a Java application via C++ and on some condition i want to suspend the same program not terminate , but suspend

    Have you tried running the virtual machine from your C++ application ? You can start Java applications from your C++ application using JNI after starting the Virtual machine from within your C++ application. According to the Java documentation you can even now stop the virtual machine from within your C++ program.
    I haven't looked at the 'suspend' detail but I suppose it will not be a problem to call a method via JNI to set a flag to suspend a thread etc.
    There is a tutorial: 'Invoking the Java Virtual Machine' at the following URL: http://java.sun.com/docs/books/tutorial/native1.1/invoking/invo.html.
    This example seems to work only for version1.1 of the JDK. For JDK1.3, version 1.2, (I am not so sure whether I fully understand Sun's version numbers for Java yet) there is some updates on the JNI for starting the VM from C++. This article is called 'JNI Enhancements'. The URL for this article is:
    http://java.sun.com/j2se/1.3.0/docs/guide/jni/jni-12.html
    You have to set version to: JNI_VERSION_1_2
    There is only one problem. I get an error when calling JNI_CreateJavaVM from C++. I could not find any documentation that indicates how you can go about diagnosing what is causing the problem. Normally in Visual C++ you can just get the probable cause by inspecting GetLastError() or the function itself can return helpful diagnostic (error) codes.
    If you manage to start the VM correctly from within Visual C++ please let me know. My email address is [email protected]
    good luck
    Henko

  • How to load java class from jsp page?

    hi all!
    Does anyone know how to load java class from jsp page?
    I try to load java class from jsp page.
    Is it possible to load java class fom jsp page?
    thanks and have a good day!

    What I mean is How to load/open java class file from jsp page?
    I think we can open Applet from jsp page by using
    <applet code=helloApplet.class width=100 height=100>
    </applet>
    but, how to open java class which is an application made by Frame?
    thanks and have a good day

  • Call a Java Application from MicroFocus COBOL (in UNIX environment)

    Hello,
    Could you please let me know, how to call a Java application from a MicroFocus COBOL application. If anyone has any code samples, that would be of great help.
    Thanks in advance,
    Tijo.

    You generally can't cause a program to be executed on a different >server. Basic security, you know. Besides this idea of having the Java >application run on a different server wasn't mentioned in your original >post. That leads me to believe we don't have the whole story.So I think you need to step back and find out what are the requirements. For example: Does your program need to start this Java application running, or is it already running and your program needs to connect to it somehow?
    My program has to start a Java class file, meaning that the Micro Focus COBOL module will call the Java class file. Will it be running on the same machine as your program, or on some other machine?
    For both cases, I would like to know the answer.a) Running on the same machine as my program is running.
    b) Running on the different machine.
    And then there are the questions about whether your program needs to have a conversation with the Java application, or whether it just needs to start it and that's all.
    COBOL program has to call a Java class by passing some parameters and Java class in turn process it and return some value back.. Kind of Request and Response model.Plenty of questions to be asked. Go and find out what they are.
    Sorry ... if I am not clear on my questions. Anyhow, thank you very much for providing the information.

  • Can we call simple a java application from any one of this AS adapters

    Can we call a simple java application from any one of this AS adapters?
    Prakash
    Message was edited by:
    user629857

    You can achieve this using LiveCycle PDF Generator JAVA API. You can find required code here:
    Adobe LiveCycle * Quick Start (SOAP mode): Converting a Microsoft Word document to a PDF document using the Java API
    In parameters:
    //Set createPDF2 parameter values
    String adobePDFSettings = "Standard";
    String securitySettings = "No Security";
    String fileTypeSettings = "Standard OCR";
    "Standard OCR" file type setting will run OCR on input pdf. In the code, instead of doc file provide a pdf file. Resultant pdf will be searchable PDF i.e OCRed PDF.
    Feel feel to ask any further questions.

  • Calling Java application from servlet

    Hi !
    I'm trying to run a Java application from within a servlet with Tomcat 4. I'm using the Runtime.getRuntime ().exec () method. So the application is run in a different JVM as a subprocess of the servlet. I use ObjectInputStream and ObjectOutputStream and a serializable object to enable communication between the servlet and the application.
    I tested the application and the serializable object with another Java application that works as the caller and it works fine. However, replacing the caller application with the servlet I get a StreamCorruptedException. The structure of the caller application and the servlet is the same.
    My questions are:
    - Is there something I should configure in Tomcat to create a subprocess ?
    - What is the cause of the StreamCorruptedException ? How do I get it with the servlet and not with the application ?
    - Should I use an environment with the call to Runtime.getRuntime ().exec () ? How do I use it ?
    - Is the called application forced to run in my servlet's context ?
    - Is there a better way to do this ?
    Thanks to all

    Here's my code:
    1. The serializable object:
    // Object Obj
    import java.io.*;
    public class Obj implements Serializable
    public int n;
    public Obj ()
    n = 0;
    public Obj (int n)
    this.n = n;
    public String toString ()
    return getClass ().getName () + " -> (n = " + n + ")";
    2. The application Sub (subprogram)
    // Application Sub
    import java.io.*;
    public class Sub
    private static File f;
    private static FileWriter fw;
    public static void main (String [] args)
    throws IOException, InterruptedException, ClassNotFoundException
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj;
    ois = new ObjectInputStream (System.in);
    obj = (Obj) ois.readObject ();
    f = new File ("Sub.txt");
    fw = new FileWriter (f);
    fw.write (obj.toString ());
    fw.close ();
    oos = new ObjectOutputStream (System.out);
    oos.writeObject (obj);
    ois.close ();
    oos.close ();
    3. The application AMain (caller application)
    // Application AMain
    import java.io.*;
    class AMain
    private static File f;
    private static FileWriter fw;
    public static void main (String [] args)
    throws IOException, ClassNotFoundException
    Runtime r;
    Process p;
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj, obj2;
    r = Runtime.getRuntime ();
    p = r.exec ("java Sub");
    oos = new ObjectOutputStream (p.getOutputStream ());
    obj = new Obj (5);
    oos.writeObject (obj);
    oos.flush ();
    B.comunica (obj);
    System.out.println ("AMain sends to Sub: " + obj.toString ());
    try
    p.waitFor ();
    catch (InterruptedException e)
    System.out.println ("Subprogram was interrupted");
    System.out.println (e.toString ());
    ois = new ObjectInputStream (p.getInputStream ());
    System.out.print ("Sub sends to AMain: ");
    obj2 = (Obj) ois.readObject ();
    System.out.println (" " + obj2.toString ());
    oos.close ();
    ois.close ();
    p.destroy ();
    4. The servlet SMain (the calling servlet)
    // Servlet SMain
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class SMain extends HttpServlet
    public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    Runtime r;
    Process p;
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj, obj2;
    int state, i;
    res.setContentType ("text/html");
    ServletOutputStream out = res.getOutputStream ();
    out.println ("<html>");
    out.println ("<head><title>Sub</title></head>");
    out.println ("<body>");
    out.println ("Invoking subprogram...");
    out.println ("<br>");
    try
    r = Runtime.getRuntime();
    p = r.exec ("java -cp .;c:\\Programs\\Apache~1.0\\webapps\\SMain\\WEB-INF\\classes Sub");
    out.println ("...invoked<br>");
    oos = new ObjectOutputStream (p.getOutputStream ());
    obj = new Obj (5);
    oos.writeObject (obj);
    oos.flush ();
    out.println ("<br>SMain sends to Sub: " + obj.toString () + "<br>");
    try
    p.waitFor ();
    catch (InterruptedException e)
    out.println ("<br>Subprogram was interrupted<br>");
    out.println ("<br>" + e.toString () + "<br>");
    state = p.exitValue ();
    out.println ("<br>Subprogram state: " + state + "<br>");
    ois = new ObjectInputStream (p.getInputStream ());
    out.print ("<br>Sub sends to SMain: ");
    obj2 = (Obj) ois.readObject ();
    p.destroy ();
    catch (SecurityException e)
    out.println ("<br>SecurityException<br>");
    out.println ("<br>" + e.toString () + "<br>");
    catch (IOException e)
    out.println ("<br>IOException<br>");
    out.println ("<br>" + e.toString () + "<br>");
    catch (Exception e)
    out.println ("<br>Exception<br>");
    out.println ("<br>" + e.toString () + "<br>");
    out.println ("</body>");
    out.println ("</html>");
    So, as you can see, both application AMain and servlet SMain invoke application Sub and pass it the serializable object Obj. Oddly enough, application AMain works fine whereas servlet SMain throws a StreamCorruptedException exception.
    johnpoole said:
    �It's hard to guess what would cause the exception without seeing code, but the interaction between the processes would differ from that between two applications, because the servlet process is started with a different class loader. I'm not sure which one the jvm started by the call would use.�
    How can I enforce that a System classloader be used in the call to Runtime.getRuntime ().exec () ? (I mean by System classloader a classloader equals to the one applications are launched from console).
    johnpoole said
    �Is there a reason why you aren't starting the second process manually and then connecting to it on a port?�
    The idea is providing a Web interface for an application running in the server. The servlet is used to restrict access to this application but once access is granted (passing the servlet) the application should not be constrained.

  • Calling Java Application from another

    How can i call a Java Application from another java App.
    eg., If my Java application is called MyApp and i would like call another java application from within it.
    One way could be by using "System". I would like to know if there is any other method and is portable.
    Thanks in advance.

    hi,
    it works and not!
    if you start an other class with a command like this the 2nd prog/class terminates too if you terminate the caller-class!
    dear
    oliver scorp

  • Calling a java application from j2ee web application

    Hi,
    I have a j2ee application in which i am making a call to a jar file which is a java application.
    Runtime a4 = Runtime.getRuntime();
    Runtime a = Runtime.getRuntime();
    String cmd[] = new String[14];
    cmd[0] = "cmd";
    cmd[1] = "/c";
    cmd[2] = "start";
    cmd[3] = "javaw";
    cmd[4] = "-jar";
    cmd[5] = CATALINA_HOME+"\\webapps\\AveksaTesting\\AveksaTestingJava\\dist\\AveksaTestingJava.jar";
    cmd[6] = SERVER_TESTS;
    cmd[7] = COLLECTOR_TESTS;
    cmd[8] = SYSTEM_TESTS;
    cmd[9] = CREATE_ORACLE;
    cmd[10] = DB_NAME;
    cmd[11] = DB_DUMP;
    cmd[12] = email;
    cmd[13] = isMIGRATE;
    try{
    java.lang.Process p = a.exec(cmd);
    Now in the called java application, i am first shutting down the tomcat server by calling shutdown.bat script and then starting it using startup.bat. But the problem i am facing is when i restart the server from java application, it says address already in use(i.e. port 8445 on which tomcat is runninng).
    Id i just call the java application and do the same operation it works fine. I guess when i am calling java from j2ee application, j2ee still has some threads holding java and not shutting down tomcat properly.
    Can anyone suggest me what can be done in this case. I have to call a java application from j2ee and restart the tomcat server many times.
    Thanks in advance
    -Vikram

    Annoyingly crossposted.
    http://forum.java.sun.com/thread.jspa?threadID=730657

  • How to call Java Beans from JSP (eg.put them in a WAR or package)

    Can anyone explain to me what are the steps and ways to call java beans from JSP?

    1st, put the javabean classes in the right place:
    the web-inf/classes/your_bean.class directory of corresponding web application
    2nd in your jsp page:
    <jsp:useBean id="obj_var_name" class="your_bean"/>
    <jsp:setProperty name="obj_var_name" property="smthg" value="smthg_calue"/>
    Micheal

  • Start Java Application

    What is the best way to start java application without a dos window ?
    And to install it

    You can create an "executable JAR file" (a JAR file which has a MANIFEST.MF file in it with some special settings) or you can start your application with "javaw" instead of "java" to prevent the DOS window from opening.
    Jesper

  • Running a Java application from a Swing GUI

    Hi,
    I was wondering if there is a simple way to run a Java application from a GUI built with Swing. I would presume there would be, because the Swing GUI is a Java application itself, technically.
    So, I want a user to click a button on my GUI, and then have another Java application, which is in the same package with the same classpaths and stuff, run.
    Is there a simple way to do this? Do any tutorials exist on this? If someone could give me any advice, or even a simple "yes this is possible, and it is simple" or "this is possible, but difficult" or "no this is not possible" answer, I would appreciate it. If anyone needs more information, I'll be happy to provide it.
    Thanks,
    Dan

    I don't know if it is possible to run the main method from another Java app by simply calling it...
    But you could just copy and paste the stuff from your main method into a new static method called something like runDBQuery and have all the execution run from there.
    How does that sound? Is it possible?
    What I'm suggeting is:
    Original
    public class DBQuery{
    public static void methodA(){
    public static void doQuery(){
    methodA();
    public static void main(String[] args){
    // Your method calls
    //Your initializing
    doQuery();
    }Revised:
    public class DBQuery{
    public static void methodA(){
    public static void doQuery(){
    methodA();
    public static void doMyQuery(){
    // Your method calls
    //Your initializing
    doQuery();
    // No main needed!!
    //public static void main(String[] args){
    // Your method calls
    //doQuery();
    //}

Maybe you are looking for

  • Cannot create PDF w/ custom page size in FM 9

    I just upgraded to the new Technical Communication Suite and cannot create a PDF from FrameMaker with a custom page size anymore. I need to create a PDF with a page size of 8.125" by 10.875", and have tried both Save As PDF and Print to the PDF drive

  • Playing Quicktime in Flash Player?

    I head that you can encode a Quicktime video as H.264 and change the extension from .mov to .flv and it will play in the Flash player. Is this true?

  • Made new html page, I cannot find an pactual font size

    Doing DW in a book, Lesson 1 made a html page "two col fixed header footer" There is a text size, an h1, h2 & <p> text size and it is 100% in the body, and 100% in the header, and after lesson #1, it is 90% in the main content, however of what?  I we

  • Import Preset Qustion or Request

    A general workflow question. This is something that has bothered me about controlling the import workflow but is there anyway to set the import location if your importing from you internal HD. I can understand it was made to behave with importing fro

  • Safari and adobe flash incompatible - mental health at risk

    Drives me mad but Safari stopped running adobe flash player months ago and I can no longer use the internet properly - can anyone help and speak english? Safari Version 5.0.4 (5533.20.27) Mac OSX 10.5.8