Java程序在Linux部署步骤如下:
sudo apt install openjdk-17-jdk。scp app.jar user@server:/path。java -jar app.jar。nohup java -jar app.jar > log.log 2>&1 &。/etc/systemd/system/app.service,内容示例:[Unit]
Description=Java App
After=network.target
[Service]
ExecStart=/usr/bin/java -jar /path/app.jar
Restart=always
User=root
[Install]
WantedBy=multi-user.target
sudo systemctl enable app.service,启动服务:sudo systemctl start app.service。sudo ufw allow 8080。注:根据项目类型(如Web应用需搭配Nginx),步骤可适当调整。