Search code examples
javaplatform

How to open a Java desktop tool from another Java application


I have created a Java desk top tool using nebeans platform module. Now we are creating a common tool from where on click of a button we should be able to launch the existing tool.

Imagine we have a JFrame and two button are present in it. One is tool1_btn Second is tool2_btn

Now when I click tool1_btn tool one should pop up.

If I write Like

try {
    String line;

    Process p = Runtime.getRuntime().exec("notepad.exe");

    /* java -classpath C:\\projects\\workspace\\testing\\bin test.TestOutput"
     * Create a buffered reader from the Process input stream.
     */
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    /**
     * Loop through the input stream to print the program output into console.
     */
    while ((line = input.readLine()) != null) {
        System.out.println(line);
    }
    /**
     * Finally close the reader
     */
    input.close();
} catch (Exception e) {
    e.printStackTrace();
}

Will pop up notepad.exe..

But if we give a Java class path for my existing tool jar it will just runs it on the back end.

I want to open the tool as if it is double clicked and opend..Is it possible..Please hlep me..

If my question is not clear inform me..


Solution

  • I do this like this: File exe = new File(...); Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + exe.getAbsolutePath());