Reputation: 3907
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
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:
exec
and use a ProcessBuilder
to create the process.URLClassLoader
pointing to the Jar, then invoke the constructor or main(String[])
of interest. If necessary, wrap the call in a SwingWorker
.Upvotes: 1