在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應用程序的遠程訪問,同時確保連接的安全性。請根據具體需求選擇合適的方法。