最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring Boot創(chuàng)建可執(zhí)行jar包的實例教程

 更新時間:2018年02月05日 16:20:13   作者:馬軍偉  
這篇文章主要介紹了Spring Boot創(chuàng)建可執(zhí)行jar包的實例教程,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

傳統(tǒng)的spring項目,可能大部分都要部署到web容器中,如Tomcat。Spring Boot提供了一種超級簡單的部署方式,就是直接將應用打成jar包,在生產(chǎn)上只需要執(zhí)行java -jar就可以運行了。

本篇文章就介紹如何創(chuàng)建可執(zhí)行jar包,以及如何部署、運行和停止。

第一步,我們需要在pom.xml添加spring-boot-maven-plugin,添加在dependecies部分下面:

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

第二步,保存pom.xml并運行mvn package命令打包:

localhost:spring-boot-tutorial-executable majunwei$ mvn package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.majunwei:spring-boot-tutorial-executable:jar:0.0.1-SNAPSHOT
[WARNING] 'parent.relativePath' of POM com.majunwei:spring-boot-tutorial-executable:0.0.1-SNAPSHOT (/Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/pom.xml) points at com.majunwei:spring-boot-tutorial instead of org.springframework.boot:spring-boot-starter-parent, please verify your project structure @ line 6, column 10
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                     
[INFO] ------------------------------------------------------------------------
[INFO] Building spring-boot-tutorial-executable 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ spring-boot-tutorial-executable ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/src/main/resources
[INFO] skip non existing resourceDirectory /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ spring-boot-tutorial-executable ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ spring-boot-tutorial-executable ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ spring-boot-tutorial-executable ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ spring-boot-tutorial-executable ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ spring-boot-tutorial-executable ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.5.6.RELEASE:repackage (default) @ spring-boot-tutorial-executable ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.380 s
[INFO] Finished at: 2017-08-04T12:01:52+08:00
[INFO] Final Memory: 21M/227M
[INFO] ------------------------------------------------------------------------

這樣就完成了打包操作,大好的包保存在target目錄里。應該在10MB左右。

localhost:target majunwei$ ls -lh
total 28232
drwxr-xr-x 4 majunwei staff  136B 8 4 11:12 classes
drwxr-xr-x 3 majunwei staff  102B 8 4 11:14 generated-sources
drwxr-xr-x 3 majunwei staff  102B 8 4 11:14 maven-archiver
drwxr-xr-x 3 majunwei staff  102B 8 4 11:14 maven-status
-rw-r--r-- 1 majunwei staff  14M 8 4 11:14 spring-boot-tutorial-executable-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 majunwei staff  3.2K 8 4 11:14 spring-boot-tutorial-executable-0.0.1-SNAPSHOT.jar.original
drwxr-xr-x 3 majunwei staff  102B 8 4 11:12 test-classes

這個包里包含了依賴的jar包、classes等信息,如果你想仔細查看這個jar包等內(nèi)容,你可以使用jar tvf命令,或解壓出來看:

$ jar tvf spring-boot-tutorial-executable-0.0.1-SNAPSHOT.jar

target目錄里還有個非常小的myproject-0.0.1-SNAPSHOT.jar.original文件。這個是Spring Boot打包之前Maven創(chuàng)建的原始jar文件。

第三步,使用java -jar命令,運行應用:

localhost:target majunwei$ java -jar spring-boot-tutorial-executable-0.0.1-SNAPSHOT.jar
 
 .  ____     _      __ _ _
 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
 ' |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::    (v1.5.6.RELEASE)
 
2017-08-04 12:05:58.917 INFO 909 --- [      main] o.s.b.tutorial.executable.Application  : Starting Application v0.0.1-SNAPSHOT on localhost with PID 909 (/Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/target/spring-boot-tutorial-executable-0.0.1-SNAPSHOT.jar started by majunwei in /Users/majunwei/Documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/target)
2017-08-04 12:05:58.926 INFO 909 --- [      main] o.s.b.tutorial.executable.Application  : No active profile set, falling back to default profiles: default
2017-08-04 12:05:59.039 INFO 909 --- [      main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@27f8302d: startup date [Fri Aug 04 12:05:59 CST 2017]; root of context hierarchy
2017-08-04 12:06:01.030 INFO 909 --- [      main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-08-04 12:06:01.050 INFO 909 --- [      main] o.apache.catalina.core.StandardService  : Starting service [Tomcat]
2017-08-04 12:06:01.053 INFO 909 --- [      main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-08-04 12:06:01.224 INFO 909 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]    : Initializing Spring embedded WebApplicationContext
2017-08-04 12:06:01.225 INFO 909 --- [ost-startStop-1] o.s.web.context.ContextLoader      : Root WebApplicationContext: initialization completed in 2199 ms
2017-08-04 12:06:01.430 INFO 909 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-08-04 12:06:01.437 INFO 909 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-08-04 12:06:01.437 INFO 909 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-08-04 12:06:01.438 INFO 909 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean  : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-08-04 12:06:01.439 INFO 909 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean  : Mapping filter: 'requestContextFilter' to: [/*]
2017-08-04 12:06:01.890 INFO 909 --- [      main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@27f8302d: startup date [Fri Aug 04 12:05:59 CST 2017]; root of context hierarchy
2017-08-04 12:06:02.019 INFO 909 --- [      main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto java.lang.String org.spring.boot.tutorial.executable.Application.home()
2017-08-04 12:06:02.024 INFO 909 --- [      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-08-04 12:06:02.024 INFO 909 --- [      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-08-04 12:06:02.062 INFO 909 --- [      main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-04 12:06:02.062 INFO 909 --- [      main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-04 12:06:02.129 INFO 909 --- [      main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-08-04 12:06:02.344 INFO 909 --- [      main] o.s.j.e.a.AnnotationMBeanExporter    : Registering beans for JMX exposure on startup
2017-08-04 12:06:02.448 INFO 909 --- [      main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-08-04 12:06:02.458 INFO 909 --- [      main] o.s.b.tutorial.executable.Application  : Started Application in 4.054 seconds (JVM running for 4.622)

第四步,跟之前一樣,想要退出應用,按ctrl-c就可以了。

下載本教程的源代碼

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • java LocalDateTime加時間,計算兩個時間的差方式

    java LocalDateTime加時間,計算兩個時間的差方式

    文章介紹了如何在Java中使用LocalDateTime類添加時間并計算兩個時間的差值,通過比較來總結(jié)個人經(jīng)驗,并鼓勵讀者參考和支持腳本之家
    2025-03-03
  • 使用maven運行Java Main的三種方法解析

    使用maven運行Java Main的三種方法解析

    這篇文章主要介紹了使用maven運行Java Main的三種方式的相關(guān)內(nèi)容,具有一定參考價值,需要的朋友可以了解下。
    2017-10-10
  • Thymeleaf對象的使用之基本對象實例解析

    Thymeleaf對象的使用之基本對象實例解析

    這篇文章主要介紹了Thymeleaf對象的使用之基本對象實例解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-04-04
  • Springboot工程中使用filter過程解析

    Springboot工程中使用filter過程解析

    這篇文章主要介紹了springboot工程中使用filter過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-03-03
  • Spring在代碼中獲取bean的方法小結(jié)

    Spring在代碼中獲取bean的方法小結(jié)

    在工作中有時候我們需要在非spring依賴注入或管理的類中獲取service、dao等bean對象,這時候用@Autowired和@Resource顯然是不行的,那么下面這篇文章就給大家了整理幾種獲取bean的方式,對大家的學習和工作具有一定的參考借鑒,下面來一起看看吧。
    2016-11-11
  • Java Math.round(),Math.ceil(),Math.floor()的區(qū)別詳解

    Java Math.round(),Math.ceil(),Math.floor()的區(qū)別詳解

    這篇文章主要介紹了Java Math.round(),Math.ceil(),Math.floor()的區(qū)別詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • SpringBoot實現(xiàn)前后端分離國際化的示例詳解

    SpringBoot實現(xiàn)前后端分離國際化的示例詳解

    Springboot國際化可以幫助使用者在不同語言環(huán)境中構(gòu)建應用程序,這樣應用程序可以有效地適應不同語言文化背景下的用戶需求。本文主要介紹了SpringBoot實現(xiàn)前后端分離國際化的方法,需要的可以參考一下
    2023-02-02
  • Java實現(xiàn)多項式乘法代碼實例

    Java實現(xiàn)多項式乘法代碼實例

    今天小編就為大家分享一篇關(guān)于Java實現(xiàn)多項式乘法代碼實例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • SpringCloud Eureka 服務注冊實現(xiàn)過程

    SpringCloud Eureka 服務注冊實現(xiàn)過程

    這篇文章主要介紹了SpringCloud Eureka 服務注冊實現(xiàn)過程,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-10-10
  • Spring MVC集成springfox-swagger2構(gòu)建restful API的方法詳解

    Spring MVC集成springfox-swagger2構(gòu)建restful API的方法詳解

    這篇文章主要給大家介紹了關(guān)于Spring MVC集成springfox-swagger2構(gòu)建restful API的相關(guān)資料,文中介紹介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-06-06

最新評論

洪江市| 建平县| 永昌县| 申扎县| 济源市| 桐城市| 桦南县| 特克斯县| 乌拉特中旗| 沂源县| 辽宁省| 繁峙县| 阿瓦提县| 武胜县| 资中县| 客服| 大城县| 贡山| 武陟县| 五大连池市| 获嘉县| 历史| 桐柏县| 美姑县| 前郭尔| 平潭县| 确山县| 特克斯县| 安龙县| 邢台县| 博兴县| 蒙阴县| 永昌县| 屏东市| 繁昌县| 绵竹市| 长寿区| 德格县| 冷水江市| 洪雅县| 贵阳市|