在Debian系统上实现Java应用程序的远程访问可以通过多种方法实现,以下是一些常见的方法和步骤:
java -agentlib:jdwptransportdt_socket,servery,suspend=n,address=*:5005 -jar demo.jar
这里以5005端口为例,suspend=n表示JVM启动时不会暂停,直到调试器连接上。Edit Configurations...。+ 号,选择 Remote JVM Debug。Name 字段中输入配置名称,在 Host 字段中输入运行Java应用程序的主机地址(如果是本机,可以使用 localhost),在 Port 字段中输入你之前设置的远程调试端口(例如:5005)。<dependency>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.2.19</version>
</dependency>
Session session = jsch.getSession(property.getUsername(), property.getHost(), property.getPort());
session.setPassword(property.getPassword());
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");
sftp.connect();
ChannelExec exec = (ChannelExec) session.openChannel("exec");
exec.setCommand(command);
InputStream in = exec.getInputStream();
exec.connect();
public interface HelloService extends Remote {
String sayHello() throws RemoteException;
}
public class HelloServiceImpl extends UnicastRemoteObject implements HelloService {
protected HelloServiceImpl() throws RemoteException {
super();
}
@Override
public String sayHello() throws RemoteException {
return "Hello, world!";
}
}
Registry registry = LocateRegistry.createRegistry(1099);
registry.bind("HelloService", new HelloServiceImpl());
Registry registry = LocateRegistry.getRegistry("localhost", 1099);
HelloService helloService = (HelloService) registry.lookup("HelloService");
String response = helloService.sayHello();
@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "Hello, world!";
}
}
curl 或其他HTTP客户端工具调用远程服务。curl http://localhost:8080/hello
sudo apt-get install xrdp
/etc/xrdp/xrdp.ini 文件,设置RDP监听端口等参数。sudo systemctl start xrdp
以上方法可以帮助您在Debian系统上实现Java应用程序的远程访问,同时确保连接的安全性。请根据具体需求选择合适的方法。