Tomasz Dzięcielewski
Tomasz Dzięcielewski

Reputation: 3907

Running separate process from Java applet using internal class

I need to run separate process from Java applet. I want to use class, which lie inside jar:

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

File MainApplet has interface Applet implementation and from inside of this code I'd like to run ProcToRun class as separete process. ProcToRun has main method.

I've tried code like this:

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

and similar (Runtime.exec(command), different notation - \\, / or with full url), but I got:

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

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

Upvotes: 3

Views: 493

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

The Java command cannot use URLs for the Jar to run, so it would be necessary to download the Jar explicitly to the local file system before attempting to run it.

But on seeing a Process, two tips:

  1. See When Runtime.exec() won't for many good tips on creating and handling a process correctly. Then ignore it refers to exec and use a ProcessBuilder to create the process.
  2. But the applet should establish an URLClassLoader pointing to the Jar, then invoke the constructor or main(String[]) of interest. If necessary, wrap the call in a SwingWorker.

Upvotes: 1

Related Questions