maven-如何使用maven对springboot项目进行打包

最近需要将springboot 的项目进行打包,其中遇见一系列问题,现进行总结:

开始步骤:

  1. 使用dos窗口进入我们项目所在的根目录:
E:\javaSource2\maven\WorkSpaces\miaoshao>
  1. 使用命令:mvn clean package 完成打包
E:\javaSource2\maven\WorkSpaces\miaoshao>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< com.miaoshaproject:miaoshao >---------------------
[INFO] Building miaoshao 1.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ miaoshao ---
[INFO] Deleting E:\javaSource2\maven\WorkSpaces\miaoshao\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ miaoshao ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 9 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ miaoshao ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 42 source files to E:\javaSource2\maven\WorkSpaces\miaoshao\target\classes
[WARNING] /E:/javaSource2/maven/WorkSpaces/miaoshao/src/main/java/com/miaoshaproject/controller/UserController.java:[14,16] sun.misc.BASE64Encoder是内部专用 API, 可能会在未来发行版中删除
[WARNING] /E:/javaSource2/maven/WorkSpaces/miaoshao/src/main/java/com/miaoshaproject/controller/UserController.java:[196,9] sun.misc.BASE64Encoder是内部专用 API, 可能会在未来发行版中删除
[WARNING] /E:/javaSource2/maven/WorkSpaces/miaoshao/src/main/java/com/miaoshaproject/controller/UserController.java:[196,41] sun.misc.BASE64Encoder是内部专用 API, 可能会在未来发行版中删除
[INFO] /E:/javaSource2/maven/WorkSpaces/miaoshao/src/main/java/com/miaoshaproject/controller/GlobalExceptionHandler.java: 某些输入文件使用了未经检查或不安全的操作。
[INFO] /E:/javaSource2/maven/WorkSpaces/miaoshao/src/main/java/com/miaoshaproject/controller/GlobalExceptionHandler.java: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ miaoshao ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\javaSource2\maven\WorkSpaces\miaoshao\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ miaoshao ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to E:\javaSource2\maven\WorkSpaces\miaoshao\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ miaoshao ---
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit4/2.22.1/surefire-junit4-2.22.1.pom
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit4/2.22.1/surefire-junit4-2.22.1.pom (3.1 kB at 1.9 kB/s)
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-providers/2.22.1/surefire-providers-2.22.1.pom
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-providers/2.22.1/surefire-providers-2.22.1.pom (2.5 kB at 4.8 kB/s)
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit4/2.22.1/surefire-junit4-2.22.1.jar
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/surefire/surefire-junit4/2.22.1/surefire-junit4-2.22.1.jar (85 kB at 117 kB/s)
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.miaoshaproject.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.04 s - in com.miaoshaproject.AppTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ miaoshao ---
[INFO] Building jar: E:\javaSource2\maven\WorkSpaces\miaoshao\target\miaoshao-1.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.469 s
[INFO] Finished at: 2019-08-03T00:07:21+08:00
[INFO] ------------------------------------------------------------------------

jar包地址:在我们对应的target 包下面会看我们对应的jar包

在这里插入图片描述

但是上面的jar包是没法运行的:

我们使用 java -jar 命令运行jar包
E:\javaSource2\maven\WorkSpaces\miaoshao\target> java -jar miaoshao-1.0.1-SNAPSHOT.jar
miaoshao-1.0.1-SNAPSHOT.jar中没有主清单属性   //没有找到main 函数


但是没有运行,实际上我们并没有将maven的pom文件中的jar包打包进行。因此我们需要在pom文件中添加以下配置

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
---------------------下面无用,只为指明地方
    </build>
</project>
再次运行打包命令:

我们发现此次生成两个jar包,第一个jar包中不仅包含我们的源代码,还包含所有依赖jar 包。所有依赖jar包以二进制资源形式打包近lib目录中。
.original后缀的包里面其实是二进制。
生成之后 .original后缀文件实际就没有用了
在这里插入图片描述

再次运行jar包

E:\javaSource2\maven\WorkSpaces\miaoshao\target> java -jar miaoshao-1.0.1-SNAPSHOT.jar
Hello World!

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.5.RELEASE)

2019-08-03 00:42:01.195  INFO 12492 --- [           main] com.miaoshaproject.App                   : Starting App v1.0.1-SNAPSHOT on LAPTOP-DHT056S0 with PID 12492 (E:\javaSource2\maven\WorkSpaces\miaoshao\target\miaosh
ao-1.0.1-SNAPSHOT.jar started by lenovo in E:\javaSource2\maven\WorkSpaces\miaoshao\target)
2019-08-03 00:42:01.219  INFO 12492 --- [           main] com.miaoshaproject.App                   : No active profile set, falling back to default profiles: default
2019-08-03 00:42:01.343  INFO 12492 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@98129: star
tup date [Sat Aug 03 00:42:01 CST 2019]; root of context hierarchy
2019-08-03 00:42:03.846  INFO 12492 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8090 (http)
2019-08-03 00:42:03.927  INFO 12492 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-08-03 00:42:03.927  INFO 12492 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2019-08-03 00:42:03.940  INFO 12492 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found o
n the java.library.path: [C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;E:\linux\ruanjian\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Pr
ogram Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Manageme
nt Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Componen
ts\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\Syste
m32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Java\jdk1.8.0_172\bin;C:\Program Files (x86)\Java\jdk1.8.0_172\jre\bin;E:\matlab\runtime\win64;E:\matlab\bin;E:\javaSource2\maven\apachemav
en\bin;E:\MySQL\mysqlanzhuang\bin;C:\Users\lenovo\AppData\Local\Microsoft\WindowsApps;C:\Users\lenovo\AppData\Local\GitHubDesktop\bin;.]
2019-08-03 00:42:04.225  INFO 12492 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-08-03 00:42:04.226  INFO 12492 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2913 ms
2019-08-03 00:42:04.416  INFO 12492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-08-03 00:42:04.417  INFO 12492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-08-03 00:42:04.417  INFO 12492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-08-03 00:42:04.417  INFO 12492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-08-03 00:42:04.417  INFO 12492 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'corsFilter' to: [/*]
2019-08-03 00:42:04.418  INFO 12492 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2019-08-03 00:42:05.409  INFO 12492 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpReq
uestHandler]
2019-08-03 00:42:05.690  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicatio
nContext@98129: startup date [Sat Aug 03 00:42:01 CST 2019]; root of context hierarchy
2019-08-03 00:42:05.789  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/register],methods=[POST],consumes=[application/x-www-form-urlencoded]}" onto public com.miaoshaproject
.response.CommonReturnType com.miaoshaproject.controller.UserController.register(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Integer,java.lang.String) throws com.miaoshaproject.error.Bu
sinessException,java.io.UnsupportedEncodingException,java.security.NoSuchAlgorithmException
2019-08-03 00:42:05.793  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/alterpassword],methods=[POST],consumes=[application/x-www-form-urlencoded]}" onto public com.miaoshapr
oject.response.CommonReturnType com.miaoshaproject.controller.UserController.alterpassword(java.lang.String,java.lang.String,java.lang.String) throws com.miaoshaproject.error.BusinessException,java.io.UnsupportedEncodin
gException,java.security.NoSuchAlgorithmException
2019-08-03 00:42:05.794  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/login],methods=[POST],consumes=[application/x-www-form-urlencoded]}" onto public com.miaoshaproject.re
sponse.CommonReturnType com.miaoshaproject.controller.UserController.login(java.lang.String,java.lang.String) throws com.miaoshaproject.error.BusinessException,java.io.UnsupportedEncodingException,java.security.NoSuchAl
gorithmException
2019-08-03 00:42:05.794  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/get]}" onto public com.miaoshaproject.response.CommonReturnType com.miaoshaproject.controller.UserCont
roller.getUser(java.lang.Integer) throws com.miaoshaproject.error.BusinessException
2019-08-03 00:42:05.796  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/otplogin],methods=[POST],consumes=[application/x-www-form-urlencoded]}" onto public com.miaoshaproject
.response.CommonReturnType com.miaoshaproject.controller.UserController.otpLogin(java.lang.String,java.lang.String) throws com.miaoshaproject.error.BusinessException
2019-08-03 00:42:05.797  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/user/getotp],methods=[POST],consumes=[application/x-www-form-urlencoded]}" onto public com.miaoshaproject.r
esponse.CommonReturnType com.miaoshaproject.controller.UserController.getOtp(java.lang.String)
2019-08-03 00:42:05.798  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/order/createorder],methods=[POST],consumes=[application/x-www-form-urlencoded]}" onto public com.miaoshapro
ject.response.CommonReturnType com.miaoshaproject.controller.OrderController.createOrder(java.lang.Integer,java.lang.Integer,java.lang.Integer) throws com.miaoshaproject.error.BusinessException
2019-08-03 00:42:05.801  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/item/getitem],methods=[GET]}" onto public com.miaoshaproject.response.CommonReturnType com.miaoshaproject.c
ontroller.ItemController.getItem(java.lang.Integer)
2019-08-03 00:42:05.801  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/item/createitem],methods=[POST],consumes=[application/x-www-form-urlencoded]}" onto public com.miaoshaproje
ct.response.CommonReturnType com.miaoshaproject.controller.ItemController.createItem(java.lang.String,java.lang.String,java.math.BigDecimal,java.lang.Integer,java.lang.String) throws com.miaoshaproject.error.BusinessExc
eption
2019-08-03 00:42:05.802  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/item/listitem],methods=[GET]}" onto public com.miaoshaproject.response.CommonReturnType com.miaoshaproject.
controller.ItemController.listItem()
2019-08-03 00:42:05.805  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Obje
ct>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-08-03 00:42:05.806  INFO 12492 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.
boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-08-03 00:42:05.858  INFO 12492 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : Detected @ExceptionHandler methods in globalExceptionHandler
2019-08-03 00:42:06.176  INFO 12492 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-08-03 00:42:06.178  INFO 12492 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2019-08-03 00:42:06.185  INFO 12492 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.alibaba.druid.pool:name=dataSource,type=DruidDat
aSource]
2019-08-03 00:42:06.359  INFO 12492 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8090 (http) with context path ''
2019-08-03 00:42:06.364  INFO 12492 --- [           main] com.miaoshaproject.App                   : Started App in 6.419 seconds (JVM running for 9.122)


发布了354 篇原创文章 · 获赞 280 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/Fly_Fly_Zhang/article/details/98259972
今日推荐