IDEA+AlibabaCloudToolkit
IDEA+AlibabaCloudToolkit
首先在 IDEA 中下载插件 Alibaba Cloud Toolkit
,这个插件更新得还蛮勤快的。主要是用来进行 ECS
等高性能服务器的部署的,咱作为个人玩家用不起 ECS
,只能买轻量应用服务器,嘎嘎香,而且 Alibaba Cloud Toolkit
也支持进在轻量应用服务器上进行部署。当然,如果你财力雄厚用的是 ECS
,那步骤也是大同小异的。
添加云主机
下载之后,在 Alibaba Cloud View
中添加云服务器,
填完之后不要忘了测试一下连接情况,主机添加完之后就可以开始部署了。
部署
右键选中你想要部署的模块,选择 Alibaba Cloud
下的 Deploy to Host
对于 After deploy
中配置的命令,这里给一个例子
lsof -i:8888 | tail -n 1 |awk '{print $2}' | xargs -i kill {} ; java -jar SpringBoot-Basic-1.0-SNAPSHOT.jar
解释一下
;
用来将两行命令拼到一行;
前半段的功能是,杀掉获取占用端口8888
的线程,;
后半段的功能是,启动 jar 包
运行
点击按钮,首先会将项目打包,然后上传到远程服务器,然后运行命令,启动项目。完美。
Mavan 打包日志:
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] Using the MultiThreadedBuilder implementation with a thread count of 20
[INFO]
[INFO] --------------------< xyz.xiashuo:SpringBoot-Basic >--------------------
[INFO] Building SpringBoot-Basic 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ SpringBoot-Basic ---
[INFO] Deleting E:\IDEAProject\SpringBoot\SpringBoot-Basic\target
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ SpringBoot-Basic ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ SpringBoot-Basic ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to E:\IDEAProject\SpringBoot\SpringBoot-Basic\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ SpringBoot-Basic ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\IDEAProject\SpringBoot\SpringBoot-Basic\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ SpringBoot-Basic ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ SpringBoot-Basic ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ SpringBoot-Basic ---
[INFO] Building jar: E:\IDEAProject\SpringBoot\SpringBoot-Basic\target\SpringBoot-Basic-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.3.4.RELEASE:repackage (repackage) @ SpringBoot-Basic ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ SpringBoot-Basic ---
[INFO] Installing E:\IDEAProject\SpringBoot\SpringBoot-Basic\target\SpringBoot-Basic-1.0-SNAPSHOT.jar to D:\Program-Dev\m2\repository_nexus_local\xyz\xiashuo\SpringBoot-Basic\1.0-SNAPSHOT\SpringBoot-Basic-1.0-SNAPSHOT.jar
[INFO] Installing E:\IDEAProject\SpringBoot\SpringBoot-Basic\pom.xml to D:\Program-Dev\m2\repository_nexus_local\xyz\xiashuo\SpringBoot-Basic\1.0-SNAPSHOT\SpringBoot-Basic-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.050 s (Wall Clock)
[INFO] Finished at: 2022-10-31T19:32:49+08:00
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "nexus" could not be activated because it does not exist.
[WARNING] The requested profile "aliyun" could not be activated because it does not exist.
Alibaba Cloud Toolkit
部署日志,先上传,然后执行命令行,启动。
[INFO] user custom command:{ null }
[INFO] IDE Version:IntelliJ IDEA 2022.2.3
[INFO] Alibaba Cloud Toolkit Version:2022.10.1-222
[INFO] started transferring file SpringBoot-Basic-1.0-SNAPSHOT.jar (16546268 bytes)
[##################################################] 100% (16546268/16546268)
[INFO] Upload Local File success
[INFO] Target Deploy Host:{ xiashuo.xyz }
[INFO] user custom command:{ source /etc/profile; cd /home/admin/webapp; lsof -i:8888 | tail -n 1 |awk '{print $2}' | xargs -i kill {} ; java -jar SpringBoot-Basic-1.0-SNAPSHOT.jar }
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.RELEASE)
2022-10-31 19:32:54.106 INFO 4175 --- [ main] xyz.xiashuo.MainApplication : Starting MainApplication v1.0-SNAPSHOT on iZbp1ag455gf8nrfdeqknwZ with PID 4175 (/home/admin/webapp/SpringBoot-Basic-1.0-SNAPSHOT.jar started by root in /home/admin/webapp)
2022-10-31 19:32:54.109 INFO 4175 --- [ main] xyz.xiashuo.MainApplication : No active profile set, falling back to default profiles: default
2022-10-31 19:32:55.212 INFO 4175 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8888 (http)
2022-10-31 19:32:55.223 INFO 4175 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-10-31 19:32:55.223 INFO 4175 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2022-10-31 19:32:55.290 INFO 4175 --- [ main] o.a.c.c.C.[.[.[/SpringBoot-Basic] : Initializing Spring embedded WebApplicationContext
2022-10-31 19:32:55.290 INFO 4175 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1081 ms
2022-10-31 19:32:55.472 INFO 4175 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2022-10-31 19:32:55.639 INFO 4175 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8888 (http) with context path '/SpringBoot-Basic'
2022-10-31 19:32:55.654 INFO 4175 --- [ main] xyz.xiashuo.MainApplication : Started MainApplication in 2.071 seconds (JVM running for 2.588)
注意
注意,我们 SpringBoot 默认使用的是 http,https 需要额外的配置。参考博客。