従来の春のプロジェクトは、主にTomcatなどのWebコンテナに展開される場合があります。 Spring Bootは、アプリケーションをJARパッケージに直接結合するための超単純な展開方法を提供し、実行するためにJava -Jarを実行するだけで実行する必要があります。
この記事では、実行可能なJARパッケージの作成方法と、展開、実行、停止する方法について説明します。
最初のステップでは、Spring-Boot-Maven-Pluginをpom.xmlに追加し、以下の依存関係セクションに追加する必要があります。
<build> <プラグイン><プラグイン> <groupId> org.springframework.boot </groupid> <artifactid> spring-boot-maven-plugin </artifactid> </plugin> </plugins> </build>
2番目のステップは、pom.xmlを保存し、MVNパッケージコマンドを実行してパッケージにすることです。
LocalHost:Spring-Boot-Tutorial-Executable Majunwei $ MVNパッケージ-dmaven.test.skip = true [info]プロジェクトのスキャン... [警告] [警告] com.majunweiの有効モデルの構築中にいくつかの問題が発生しました:Spring-boot-tutorial-executable:jar:0.0.1-snapshot 'pom.Relate com.majunwei:spring-boot-tutorial-executable:0.0.1-snapshot(/users/majunwei/documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/pom.xml) org.springframework.boot:spring-boot-starter-parent、プロジェクト構造を確認してください @行6、列10 [警告] [警告]建物の安定性を脅かすため、これらの問題を修正することを強くお勧めします。 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /users/majunwei/documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/src/main/resources [info]スキップ既存のResourcedirectory/Majunwei/documents/work/spring-boot-tutorial/spring-boot-tutorial-exutable/src/main/resource Maven-compiler-plugin:3.1:compile(default-compile) @ spring-boot-tutorial-executable - [info] compile-すべてのクラスは最新の[情報] [情報] --- maven-resources-plugin:2.6:testResours(default-testresources) @ spring-boot-exextiable- [info] notexecutable-notexecutable- [info] notexecutable- [Info] extuteable-extuteable-exture-extible-exture-copy) Maven-Compiler-Plugin:3.1:TestCompile(Default-TestCompile) @ Spring-Boot-Tutorial-Executable --- [情報]テストソースをコンパイルしない[情報] [情報] --- Maven-Surefire-Plugin:2.18.1:Test(Default-Test) @ Spring-Tutorial-Executable- 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]] ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
これにより、パッケージ操作が完了し、ターゲットディレクトリの大きなパッケージを保存します。約10MBでなければなりません。
LocalHost:Target Majunwei $ LS -LHTOTAL 28232DRWXR-XR-X 4 MAJUNWEIスタッフ136B 8 4 11:12 CLASSESDRWXR-XR-X 3 MAJUNWEI STAFF 8 4 11:14 Majunwei Staff 102b 8 4 11:14 Maven-Status-RW-R --- 1 Majunwei Staff 14M 8 4 11:14 Spring-Boot-Tutorial-Executable-0.0.1-Snapshot.jar-Rw-r --- 1 Majunweiスタッフ3.2k 8 4 11:14 Spring-Boot-Tutorial-Executable-0.0.1-Snapshot.jar.originaldrwxr-xr-x 3 Majunweiスタッフ102b 8 4 11:12テストクラス
このパッケージには、依存するJARパッケージ、クラス、その他の情報が含まれています。このJARパッケージの内容を慎重に表示する場合は、JAR TVFコマンドを使用するか、次を解除してください。
$ JAR TVF Spring-Boot-Tutorial-Executable-0.0.1-Snapshot.jar
ターゲットディレクトリには、MyProject-0.0.1-Snapshot.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.jar.originalの非常に小さなファイルもあります。これは、Spring Bootがパッケージ化される前にMavenによって作成された元のJARファイルです。
3番目のステップは、Java -Jarコマンドを使用してアプリケーションを実行することです。
LocalHost:Majunwei $ Java -Jar Spring-Boot-Tutorial-Executable-0.1-Snapshot.jar。 ____ __ _ /// / ___'_ __ _ _ _ _(_)_ __ __ __ __ _ _ _ _ _ _ _ _ _ / / / /(() / ___ | '_ |' _ // _` | / / / / / / / / / / / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | .__ | | _ | | _ | | =================================================/_/_/_/:: spring boot:(v1.5.6.release) v0.0.1-snapshot on localhost on pid 909(/users/majunwei/documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/target/spring-boot-tutorial-executable-0.0.1-snapshot.jar /users/majunwei/documents/work/spring-boot-tutorial/spring-boot-tutorial-executable/target)2017-08-04 12:05:58.926 Info 909 --- [Main] Osbtutorial.executable.Application:アクティブなプロファイルはありません。 main] ationConfigemdedwebapplicationContext:resuphing org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@27f8302d:起動日[2017年8月4日12:05:59 CST 2017];コンテキストのルートhierarchy2017-08-04 12:06:01.030 Info 909 - [main] sbcettomcatembeddedservletcontainer:ポートで初期化:8080(http)2017-08-04 12:06:06:01050情報909-- [メイン] o.apache.catalina.core.standardservice:Starting Service [Tomcat] 2017-08-04 12:06:01.053 Info 909 --- [Main] org.apache.catalina.core.standardengine:スターティングサーブレットエンジン:Apache Tomcat/8.5.162017-08-0412:01.224:06:06:06:06:06:06:06: [OST-StartStop-1] occc [tomcat]。[localhost]。 12:06:01.430 INFO 909 --- [OST-STARTSTOP-1] OSBWSERVLET.SERVLETREGISTRATIONBEAN:マッピングサーブレット:「DispatcherServlet」から[/] 2017-08-04 12:06:01.437 INFO 909 'charatereCodingFilter' to:[/*] 2017-08-04 12:06:01.437 INFO 909 --- [OST-STARTSTOP-1] OSBWSERVLET.FILTERREGISTRATIONBEAN:MAPPING FILTER: 'HIDDEDHTTPMETHODFILTER' to:[/*] 2017-08-04 12:06.438 [OST-STARTSTOP-1] OSBWSERVLET.FILTERREGISTRATIONBEAN:マッピングフィルター: 'httpputformContentFilter' to:[/*] 2017-08-04 12:06:01.439 Info 909 --- [OST-STARTSTOP-1] OSBWSERVLET.FILTERREGINTEXT.FILTERREGINTEXT: 'MAPTEXT:MAPTING MAPTING FINT:MAPTEN [/*] 2017-08-04 12:06:01.439 INFO 909 --- [OST-STARTSTOP-1] OSBWSERVLET.FILTERREGISTRATIONBEAN:マッピングフィルター:[/*] 2017-08-04 12:06:01.890情報@controlleradvice:org.springframework.boot.context.embedded.annotationConfigemdedwebapplicationContext@27F8302D:起動日[Fri Aug 04 12:05:59 CST 2017];コンテキストのroot hierarchy2017-08-04 12:06:02.019 Info 909 --- [Main] SWSMAREQUESTMAPPINGHANDLERMAPPING:java.lang.String org.spring.boot.boot.tutorial.executable.home.home.home()2017-04:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06情報909 --- [メイン] SWSMAREQUESTMAPPINGHANDLERMAPPING:MAPPED "{[/error]}" to 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-- [メイン] SWSMMAREQUESTMALPINGMAPPING HANDLERMAPPING:MAPED "{[/error]、produces = [text/html]}" "to public org.springframework.web.servlet.modelandviewへorg.springframework.autoconfigure.web.basicerrorcontroller.errorhtml(javax.servlet.http.httpservletrequest、javax.servlet.http.httpservletresponse) oswshandler.simpleurlhandlermapping:マッピングされたURLパス[/webjars/**]タイプのハンドラーに[クラスorg.springframework.web.servlet.resource.resourcehttprequesthandler] 2017-08-04 12:06:02.062情報[クラスorg.springframework.web.servlet.resource.resourcehttprequesthandler] 2017-08-04 12:06:02.129 INFO 909 - 02.129のタイプのハンドラーにマッピングされたURLパス[/**]タイプのハンドラー[class org.springframework.web.servlet.resource.resourcehtprequesthandler] 2017-08-04 12:06:02.344 Info 909 --- [Main] Osjeaannotationmbeanexporter:JMX露出のための豆の登録--- [メイン] sbcettomCatemBededServletContainer:Tomcatはポートで開始されました:8080(http)2017-08-04 12:06:02.458 INFO 909 - [MAIN] OSBTUTORIAL.EXECUTABLE.APPLICITION:4.054秒のアプリケーションを開始(4.622)ステップ4:前と同じように、アプリケーションを終了する場合は、CTRL-Cを押します。
このチュートリアルのソースコードをダウンロードします
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。