SpringBoot建立web視覺化:(5)打jar包部署到伺服器
阿新 • • 發佈:2019-01-12
1.實現功能
將springBoot打包jar包,放入生產環境中執行
2.打包命令
(1)使用cmd命令進入專案根目錄
e:
cd E:\Tools\WorkspaceforMyeclipse\Webproject
(2)執行編譯命令
mvn clean package -DskipTests 結果: [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ web --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ web --- [INFO] Building jar: e:\Tools\WorkspaceforMyeclipse\WebSpring\target\web-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- spring-boot-maven-plugin:2.0.5.RELEASE:repackage (default) @ web --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 21.226 s [INFO] Finished at: 2018-11-25T22:31:39+08:00 [INFO] Final Memory: 44M/275M [INFO] ------------------------------------------------------------------------
(3)在E:\Tools\WorkspaceforMyeclipse\WebSpring\target目錄下找到
web-0.0.1-SNAPSHOT.jar
3.拷貝到linux目錄
/opt/datas/streamingproject/web-0.0.1-SNAPSHOT.jar
4.執行
java -jar web-0.0.1-SNAPSHOT.jar
5.報錯分析
(1)報錯
Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[/imooc]]和之前一樣,因為jar包衝突 檢視報錯資訊最後,有: jar:file:/opt/datas/streamingproject/web-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/servlet-api-2.5.jar!/javax/servlet/ServletContext.class jar:file:/opt/datas/streamingproject/web-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/tomcat-embed-core-8.5.34.jar!/javax/servlet/ServletContext.class
原因:jar包衝突
解決:開啟web-0.0.1-SNAPSHOT.jar,刪除lib下面servlet-api-2.5.jar(注意:重新命名servlet-api-2.5.jar為servlet-api-2.5-backup.jar不可行,自己嘗試過。)然後儲存,然後重新上傳
6.測試執行(成功~)
[[email protected] streamingproject]# java -jar web-0.0.1-SNAPSHOT.jar
18/11/25 22:59:07 INFO util.Version: HV000001: Hibernate Validator 6.0.12.Final
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)
18/11/25 22:59:07 INFO imooc.WebApplication: Starting WebApplication v0.0.1-SNAPSHOT on hadoop with PID 31481 (/opt/datas/streamingproject/web-0.0.1-SNAPSHOT.jar started by root in /opt/datas/streamingproject)
18/11/25 22:59:07 INFO imooc.WebApplication: No active profile set, falling back to default profiles: default
18/11/25 22:59:07 INFO context.AnnotationConfigServletWebServerApplicationContext: Refreshing org.springframework.boot.web.ser [email protected]5f205aa: startup date [Sun Nov 25 22:59:07 CST 2018]; root of context hierarchy
18/11/25 22:59:08 INFO tomcat.TomcatWebServer: Tomcat initialized with port(s): 9999 (http)
Nov 25, 2018 10:59:08 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
Nov 25, 2018 10:59:08 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.34
Nov 25, 2018 10:59:08 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
Nov 25, 2018 10:59:08 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring embedded WebApplicationContext
18/11/25 22:59:08 INFO context.ContextLoader: Root WebApplicationContext: initialization completed in 1545 ms