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.测试运行(成功~)
[root@hadoop 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.servlet.context.AnnotationConfigServletWebServerApplicationContext@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