Starting a separate process from a Java applet using an inner class

I need to start a separate process from a Java applet. I want to use the class inside the jar:

myApplet.jar
 - packagename.MainApplet.class
 - packagename.ProcToRun.class

      

The file MainApplet

has an applet implementation interface and from within this code I would like to run the class ProcToRun

as a separete process. ProcToRun has a main method.

I've tried code like this:

Process p = new ProcessBuilder("java", "-cp", ".;./myApplet.jar", ProcToRun.class.getName()).start();

      

and similar ones ( Runtime.exec(command)

, different notation is \\, / or with full url), but I got:

Error: Could not find or load main class packageagename.ProcToRun

Java.exe visible, applet signed - have all permissions using win 8.1, java 8 u 25. I think there is something wrong with the classpath, but I can't seem to find a solution.

+3


source to share


1 answer


The Java team cannot use URLs to run the Jar, so it will need to download the Jar to the local filesystem first before trying to run it.

But after seeing Process

two clues:



  • See When Runtime.exec () Will Not For many good advice on how to properly create and handle a process. Then ignore what it refers to exec

    and uses ProcessBuilder

    to create the process.
  • But the applet has to install the URLClassLoader

    pointing to Jar and then call the constructor or the main(String[])

    one of interest. If necessary, wrap the call in SwingWorker

    .
+1


source







All Articles