spring boot 鎵搄ar鍖呭垎绂籰ib鍜宺esources

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot 鎵搄ar鍖呭垎绂籰ib鍜宺esources相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%bc%a0%e8%be%93' title='浼犺緭'>浼犺緭   ring   includes   with   output   缂栬緫   绋嬪簭   one   鏂规硶   

涓轰粈涔堣閰嶇疆銆佷緷璧栨枃浠跺垎绂伙細

1.鍦ㄤ紶缁焜ar鍖呬腑锛屾墍鏈夋枃浠堕兘鎵撳寘鍒颁竴涓猨ar鍖呬腑锛宩ar闈炲父鑷冭偪锛屽湪杩涜鏈嶅姟鏇存柊閮ㄧ讲鏃堕潪甯镐笉渚匡紝鑰屼笖浼犺緭涓嶇ǔ瀹氭椂瀵艰嚧浼犺緭澶辫触銆傚鏋滆繃瀹炶鏂囦欢鍒嗙銆佸湪渚濊禆涓嶆敼鍙樼殑鎯呭喌涓嬶紝浠呬粎涓婁紶鏇存柊鍚庣殑 缂栬瘧鏂囦欢鏄潪甯告柟渚跨殑銆?/p>

  1. 濡傛灉瑕佷慨鏀逛竴浜涢厤缃枃浠讹細properties銆亁ml锛岄潤鎬佹枃浠剁瓑鍙互鐩存帴鍦ㄦ湇鍔″櫒涓婄紪杈戙€?/li>

閭d箞鎬庝箞瀹炶閰嶇疆銆佷緷璧栨枃浠跺垎绂诲憿锛?/h2>

鎻掍欢浠嬬粛

  1. maven-jar-plugin 杩欎釜鎻掍欢寮忎笓闂ㄧ敤鏉ユ墦鍖呯敤鐨勶紝鍙互閰嶇疆闇€瑕佹墦鍖呰繘鍘荤殑鏂囦欢锛岀▼搴忕殑鍏ュ彛绫荤瓑銆?/li>
  2. maven-resources-plugin 杩欎釜鎻掍欢鏄敤鏉ユ嫹璐濊祫婧愭枃浠剁殑銆?/li>
  3. maven-maven-dependency-plugin 杩欎釜鎻掍欢鏄敤鏉ユ嫹璐濅緷璧栧簱鐨勩€?/li>
  4. maven-assembly-plugin 鍙互璇村寘鍚簡浠ヤ笂鎻掍欢鐨勫姛鑳斤紝浣嗘槸鍙互鍋氬埌鏇寸簿缁嗙殑鎺у埗銆?/li>
  5. spring-boot-maven-plugin 杩欎釜涓嶇敤璇达紝springboot 椤圭洰鏈€閲嶈鐨勬彃浠讹紝鏁翠釜椤圭洰鐨勬墦鍖呭鐞嗚繃绋嬭繕鏄渚濋檮浜庡畠銆?/li>

鎵撳寘鎴愬彲鎵цjar锛屼笉浠呬粎灞€闄怱pringBoot椤圭洰锛堜富鍏ュ彛鍑芥暟瀛樺湪锛?/h3>

maven-jar-plugin 鎻掍欢鎵撳寘jar

鍦╬om鏂囦欢涓厤缃?浣嗘槸杩欐牱 渚濊禆鐨刯ar骞朵笉浼氭墦杩涙潵锛堝悗闈細鏈夎В鍐虫柟娉曪級,閫傜敤涓嶉渶瑕佷緷璧栨枃浠剁殑椤圭洰銆?/p>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3</version>


                <configuration>
                    <archive>
                        <manifest>

                            <!--鏄惁娣诲姞渚濊禆-->
                            <addClasspath>true</addClasspath>

                            <!--璁剧疆鍚姩绫?->
                            <mainClass>xxx.xxx.Main</mainClass>

                        </manifest>
                    </archive>
                    <!--璁剧疆鐢熸垚jar杈撳嚭浣嶇疆-->
                    <outputDirectory>${project.build.directory}</outputDirectory>

                </configuration>
            </plugin> 

maven-assembly-plugin 鎻掍欢鎵撳寘jar

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>

                    <!--涓嶆坊鍔燗ssemblyId-->
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptorRefs>
                        <!--閰嶇疆鎵撳寘鐨勬椂鍊欎竴骞舵墦鍖呬緷璧杍ar-->
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <!--鍏ュ彛绫?->
                            <mainClass>xxx.xxx.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!--缁戝畾鐢熷懡鍛ㄦ湡-->
                        <phase>package</phase>
                        <goals>
                            <!--鎵цassembly -->
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

鎵撳寘SpringBoot 椤圭洰

鏂规涓€銆?/h4>
<plugins>
        <!--鎵撳寘jar-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
               
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <!--MANIFEST.MF 涓?Class-Path 鍔犲叆鍓嶇紑-->
                        <classpathPrefix>lib/</classpathPrefix>
                        <!--jar鍖呬笉鍖呭惈鍞竴鐗堟湰鏍囪瘑-->
                        <useUniqueVersions>false</useUniqueVersions>
                        <!--鎸囧畾鍏ュ彛绫?->
                        <mainClass>xxx.xxx.Application</mainClass>
                    </manifest>
                    <manifestEntries>
                        <!--MANIFEST.MF 涓?Class-Path 鍔犲叆璧勬簮鏂囦欢鐩綍-->
                        <Class-Path>/resources</Class-Path>
                    </manifestEntries>
                </archive>
                <outputDirectory>${project.build.directory}/dis</outputDirectory>
            </configuration>
        </plugin>

        <!--鎷疯礉渚濊禆 copy-dependencies-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                                ${project.build.directory}/dis/lib/
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--鎷疯礉璧勬簮鏂囦欢 copy-resources-->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>src/main/resources</directory>
                                </resource>
                            </resources>
                            <outputDirectory>${project.build.directory}/dis/resources</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--spring boot repackage锛屼緷璧?maven-jar-plugin 鎵撳寘鐨刯ar鍖?閲嶆柊鎵撳寘鎴?spring boot 鐨刯ar鍖?->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                 
                    <layout>ZIP</layout>
                    <!--浣跨敤澶栭儴閰嶇疆鏂囦欢锛宩ar鍖呴噷娌℃湁璧勬簮鏂囦欢-->
                    <addResources>true</addResources>
               
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

鏂规浜?/p>

杩欓噷渚濊禆assembly.xml 鎻忚堪鏂囦欢

                <plugins>
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                            <outputDirectory>${project.build.directory}/dist/</outputDirectory>
                        </configuration>
                        <executions>
                            <execution>
                                <id>make-assembly</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- 鎵撳寘鎴恓ar鏂囦欢锛屽苟鎸囧畾lib鏂囦欢澶逛互鍙妑esources璧勬簮鏂囦欢澶?-->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>xxx.xxx.Application</mainClass>
                                    <!--渚濊禆鍓嶇紑-->
                                    <classpathPrefix>lib/</classpathPrefix>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                                <manifestEntries>
                                    <Class-Path>resources/</Class-Path>
                                </manifestEntries>
                            </archive>
                        </configuration>
                    </plugin>
                </plugins>

assembly.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <id>distribution</id>

    <!--杈撳嚭鏍煎紡 zip 鏈€缁堢粨鏋滅敓鎴恴ip -->
    <formats>
        <format>zip</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <!--璁剧疆闇€瑕佽緭鍑烘枃浠?->
    <fileSets>
        <fileSet>
            <directory>src/main/resources/</directory>
            <outputDirectory>/resources</outputDirectory>
        </fileSet>
    
    </fileSets>

    <dependencySets>
        <dependencySet>
            <!--渚濊禆鍖呯殑杈撳嚭鐩綍-->
            <outputDirectory>/lib</outputDirectory>
            <scope>runtime</scope>
            <excludes>
                <exclude>${project.groupId}:${project.artifactId}</exclude>
            </excludes>
        </dependencySet>
        <dependencySet>
            <!--jar鍖呯殑杈撳嚭鐩綍-->
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>${project.groupId}:${project.artifactId}</include>
            </includes>
        </dependencySet>
    </dependencySets>
</assembly>

 

以上是关于spring boot 鎵搄ar鍖呭垎绂籰ib鍜宺esources的主要内容,如果未能解决你的问题,请参考以下文章

AWS Elastic Beanstalk Spring Boot fat JAR:找不到jsp

Spring Boot

spring boot 集成 Redis

Spring Boot 基本认证

spring boot整合Thymeleaf

spring boot - 整合jpa