问题描述
我目前正在使用 WSL 在 VSC 中开发一个简单的 RMI 应用程序。但是,当我使用自定义 launch.json
运行具有 VSC 内置运行和调试功能的应用程序时,它无法执行并给我一个错误。
Server.java
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server extends UnicastRemoteObject implements Interface{
public static void main(String[] args) {
try {
System.setProperty("java.security.policy","file:./security.policy");
System.setSecurityManager(new SecurityManager());
Server server = new Server();
Naming.rebind("Server",server);
System.out.println("Service registered");
} catch (Exception error) {
error.printStackTrace();
System.exit(0);
}
}
public Server() throws RemoteException {
super(0);
System.out.println("Server is started");
}
public boolean login(String username,String password) throws RemoteException {
System.out.println("Received login request");
return true;
}
public boolean register(String username,String password) throws RemoteException {
System.out.println("Received register request");
return true;
}
}
Interface.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Interface extends Remote {
boolean login(String username,String password) throws RemoteException;
boolean register(String username,String password) throws RemoteException;
}
launch.json
{
"version": "0.2.0","configurations": [
{
"type": "java","name": "Launch Server","request": "launch","mainClass": "com.project.Server","projectName": "project","args": "-Djava.rmi.server.useCodebaseOnly=false"
}
]
}
Folder structure
root
|_src
|_main
|_java
|_com
|_project
|_Client.java
|_Interface.java
|_Server.java
|_other files..omitted for simplicity
我也将文件夹添加到了 VSC 中的 Java 源路径
我的执行步骤
1. run rmiregistry &
2. click Launch Server in VSC debug and run
我遇到的错误是
Caused by: java.lang.ClassNotFoundException: com.project.Interface
VSC 运行 RMI 应用程序的能力是否受到限制?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)