前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >springBoot 怎么利用maven 创建可以执行的jar文件?

springBoot 怎么利用maven 创建可以执行的jar文件?

作者头像
爱明依
发布2019-03-12 15:18:58
1K0
发布2019-03-12 15:18:58
举报
文章被收录于专栏:爱明依爱明依

1 为了可以使用maven 创建可执行的jar文件 ,首先需要再pom.xml 加入如下的依赖。

<build>     <plugins>         <plugin>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-maven-plugin</artifactId>         </plugin>     </plugins> </build>

1、win+r 打开命令行窗口

2、切换到主pom文件所在位置:

3、执行相应的命令:

$ mvn package [INFO] Scanning for projects... [INFO] [INFO] ----------------------------------------------------------------------- [INFO] Building myproject 0.0.1-SNAPSHOT [INFO] ----------------------------------------------------------------------- [INFO] .... .. [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ myproject -- [INFO] Building jar: /Users/developer/example/spring-boot-example/target/myproject-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- spring-boot-maven-plugin:1.5.9.RELEASE:repackage (default) @ myproject -- [INFO] ----------------------------------------------------------------------- [INFO] BUILD SUCCESS [INFO] -----------------------------------------------------------------------

4 运行jar

使用 java -jar 命令

$ java -jar target/myproject-0.0.1-SNAPSHOT.jar   .   ____          _            __ _ _  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )   '  |____| .__|_| |_|_| |_\__, | / / / /  =========|_|==============|___/=/_/_/_/  :: Spring Boot ::  (v1.5.9.RELEASE) ....... . . . ....... . . . (log output here) ....... . . . ........ Started Example in 2.536 seconds (JVM running for 2.864)

控制太示例

----------

Microsoft Windows [版本 10.0.15063] (c) 2017 Microsoft Corporation。保留所有权利。

C:\Users\wo> cd cd C:\框架研究\demo\targetC:\框架研究\demo\target 文件名、目录名或卷标语法不正确。

C:\Users\wo>cd C:\框架研究\demo\targetC:\框架研究\demo\target 文件名、目录名或卷标语法不正确。

C:\Users\wo>cd C:\框架研究\demo

C:\框架研究\demo>mvn package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building demo 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\框架研究\demo\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demo --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ demo --- [INFO] [INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ demo --- [INFO] Building jar: C:\框架研究\demo\target\demo-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- spring-boot-maven-plugin:1.5.9.RELEASE:repackage (default) @ demo --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.501 s [INFO] Finished at: 2017-12-12T09:37:03+08:00 [INFO] Final Memory: 21M/267M [INFO] ------------------------------------------------------------------------

C:\框架研究\demo> cd target

C:\框架研究\demo\target>java -jar demo-0.0.1-SNAPSHOT.jar

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

2017-12-12 09:39:41.581  INFO 10088 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on DESKTOP-GDID72D with PID 10088 (C:\妗嗘灦鐮旂┒\demo\target\demo-0.0.1-SNAPSHOT.jar started by wo in C:\妗嗘灦鐮旂┒\demo\target) 2017-12-12 09:39:41.596  INFO 10088 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default 2017-12-12 09:39:41.706  INFO 10088 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6659c656: startup date [Tue Dec 12 09:39:41 CST 2017]; root of context hierarchy 2017-12-12 09:39:43.675  INFO 10088 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 2017-12-12 09:39:43.690  INFO 10088 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat] 2017-12-12 09:39:43.690  INFO 10088 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.23 2017-12-12 09:39:43.846  INFO 10088 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext 2017-12-12 09:39:43.846  INFO 10088 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2140 ms 2017-12-12 09:39:44.034  INFO 10088 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/] 2017-12-12 09:39:44.050  INFO 10088 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*] 2017-12-12 09:39:44.050  INFO 10088 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2017-12-12 09:39:44.050  INFO 10088 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2017-12-12 09:39:44.050  INFO 10088 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*] 2017-12-12 09:39:44.425  INFO 10088 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6659c656: startup date [Tue Dec 12 09:39:41 CST 2017]; root of context hierarchy 2017-12-12 09:39:44.534  INFO 10088 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto java.lang.String com.example.demo.DemoApplication.home() 2017-12-12 09:39:44.534  INFO 10088 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2017-12-12 09:39:44.534  INFO 10088 --- [           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.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2017-12-12 09:39:44.581  INFO 10088 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-12-12 09:39:44.581  INFO 10088 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-12-12 09:39:44.628  INFO 10088 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-12-12 09:39:44.800  INFO 10088 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup 2017-12-12 09:39:44.878  INFO 10088 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 2017-12-12 09:39:44.878  INFO 10088 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 3.938 seconds (JVM running for 4.469) 2017-12-12 09:39:49.945  INFO 10088 --- [nio-8080-exec-1] o.apache.tomcat.util.http.parser.Cookie  : A cookie header was received [1512958808] that contained an invalid cookie. That cookie will be ignored.Note: further occurrences of this error will be logged at DEBUG level. 2017-12-12 09:39:49.956  INFO 10088 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet' 2017-12-12 09:39:49.956  INFO 10088 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started 2017-12-12 09:39:49.982  INFO 10088 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 26 ms

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年12月11日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档