这是一个网络应用程序,每件事都打包在战争中。
我能够将一个名为remote_proxy-1.0.0.jar
的本地jar安装到我的maven项目中(它包含在生成的工件的WEB-INF/lib
目录中)。此jar文件包含接口Task
和TaskRunner
以及TaskRunner
实现类TaskRunnerRemoteObject
。一切都在编译,应用程序可以部署。下面是用于启动RMI服务器的引导代码
package rmi;
import java.io.*;
import java.nio.file.*;
import java.util.logging.*;
import static java.util.stream.Collectors.joining;
import java.util.stream.Stream;
import javax.enterprise.concurrent.ManagedExecutorService;
public class ProcessInit {
public static Process startRMIServer(ManagedExecutorService pool, String WEBINF, int port, String jar) {
ProcessBuilder pb = new ProcessBuilder();
Path wd = Paths.get(WEBINF);
pb.directory(wd.resolve("classes").toFile());
Path lib = wd.resolve("lib");
String cp = Stream.of("javabuilder.jar", "remote_proxy.jar", jar)
.map(e -> lib.resolve(e).toString())
.collect(joining(File.pathSeparator));
pb.command("java", "-cp", "." + File.pathSeparator + cp, "rmi.BootStrap", String.valueOf(port));
while (true) {
try {
Process p = pb.start();
pool.execute(() -> flushIStream(p.getInputStream()));
pool.execute(() -> flushIStream(p.getErrorStream()));
return p;
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Retrying....");
}
}
}
private static void flushIStream(InputStream is) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
br.lines().forEach(System.out::println);
} catch (IOException ex) {
Logger.getLogger(ProcessInit.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public class BootStrap {
public static void main(String[] args) {
int port = Integer.parseInt(args[0]);
System.out.println("Instantiating a task runner implemenration on port: " + port );
try {
System.setProperty("java.rmi.server.hostname", "localhost");
TaskRunner runner = new TaskRunnerRemoteObject();
TaskRunner stub = (TaskRunner)UnicastRemoteObject.exportObject(runner, 0);
Registry reg = LocateRegistry.createRegistry(port);
reg.rebind("runner" + port, stub);
} catch (RemoteException ex) {
Logger.getLogger(BootStrap.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
内部WEB-INF/lib
当这个类被执行时,它会抛出这个我不明白的错误,因为本地jar remote_proxy-1.0.0.jar
包含在类路径中,我没有任何编译错误,但仍然得到这个异常。
Caused by: java.lang.ClassNotFoundException: remote_proxy.TaskRunnerRemoteObject