Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 420
Tomasz Dzięcielewski Avatar asked Jul 27 '26 08:07

Tomasz Dzięcielewski


1 Answers

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.
like image 154
Andrew Thompson Avatar answered Jul 29 '26 23:07

Andrew Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!