国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

11.5 創(chuàng)建可執(zhí)行程序(Executable Jar)

2018-08-14 15:05 更新

We finish our example by creating a completely self-contained executable jar file that we could run in production. Executable jars (sometimes called “fat jars”) are archives containing your compiled classes along with all of the jar dependencies that your code needs to run. 我們通過創(chuàng)建一個可以在生產(chǎn)中運行的完全獨立的可執(zhí)行JAR文件來完成我們的示例。 可執(zhí)行jar(有時候叫做“fat jar”)是一個歸檔(壓縮)文件,包含了編譯的類以及為運行您的代碼所依賴的所有jar包。

Executable jars and Java
可執(zhí)行jar和Java

Java does not provide a standard way to load nested jar files (jar files that are themselves contained within a jar). This can be problematic if you are looking to distribute a self-contained application.
Java沒有提供一個標(biāo)準(zhǔn)的方式去加載一個內(nèi)嵌jar文件(jar文件本身包含在一個jar文件中)。 如果您想發(fā)布一個獨立的應(yīng)用程序,這可能是有問題的。

To solve this problem, many developers use “uber” jars. An uber jar packages all the classes from all the application’s dependencies into a single archive. The problem with this approach is that it becomes hard to see which libraries are in your application. It can also be problematic if the same filename is used (but with different content) in multiple jars.

為解決這個問題, 許多開發(fā)者使用“uber” jar。 一個“uber”jar打包了所有這個應(yīng)用程序依賴的類文件到一個單獨的歸檔(壓縮)文件中。 這種方法帶來的問題是很難看出這個應(yīng)用程序中有哪些庫。 如果在多個jar包中使用了相同文件名(但是擁有不同內(nèi)容),這將是有問題的。

Spring Boot takes a different approach and lets you actually nest jars directly.
SpringBoot采取了一個不同方法, 可以讓您直接內(nèi)嵌jar包。

To create an executable jar, we need to add the spring-boot-maven-plugin to our pom.xml. To do so, insert the following lines just below the dependencies section: 為了創(chuàng)建一個可執(zhí)行Jar, 我們需要添加spring-boot-maven-plugin到我們的 pom.xml。如此, 僅在dependencies節(jié)點后面,插入下面幾行(代碼):

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

說明

The spring-boot-starter-parent POM includes <executions& configuration to bind the repackage goal. If you do not use the parent POM, you need to declare this configuration yourself. See the plugin documentation for details.
spring-boot-starter-parentPOM中包含了<executions>配置信息,綁定了repackage goal。 如果不使用這個父POM, 您需要聲明您自己的配置信息。 參見插件文檔獲取更多細(xì)節(jié)。

Save your pom.xml and run mvn package from the command line, as follows: 保存您的pom.xml,命令行中運行mvn package, 如下所示:

$ 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:2.0.3.RELEASE:repackage (default) @ myproject ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

If you look in the target directory, you should see myproject-0.0.1-SNAPSHOT.jar. The file should be around 10 MB in size. If you want to peek inside, you can use jar tvf(命令),如下所示:, as follows: 如果您查看 target目錄, 您會看見myproject-0.0.1-SNAPSHOT.jar。這個文件大概10M大小。 如果您想查看(包)內(nèi)容, 您可以使用 jar tvf(命令),如下所示:

$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar

You should also see a much smaller file named myproject-0.0.1-SNAPSHOT.jar.original in the target directory. This is the original jar file that Maven created before it was repackaged by Spring Boot. 在target目錄下,您應(yīng)該還看到了小很多名叫myproject-0.0.1-SNAPSHOT.jar.original的文件。這是源Jar文件,它由Maven在SpringBoot重新打包之前創(chuàng)建的。

To run that application, use the java -jar command, as follows: 為了運行那個應(yīng)用程序, 請使用java -jar命令, 如下所示:

$ java -jar target/myproject-0.0.1-SNAPSHOT.jar


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v2.0.3.RELEASE)
....... . . .
....... . . . (log output here)
....... . . .
........ Started Example in 2.536 seconds (JVM running for 2.864)

As before, to exit the application, press ctrl-c. 就像之前所述, 要退出應(yīng)用程序,請按下ctrl-c

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號