maven打包以及配置分離

來源:互聯網
上載者:User

標籤:


按住shift 點擊滑鼠右鍵,點擊“在此處開啟命令視窗”,在視窗中輸入“mvn package”,如

我的沒有配環境,要在maven安裝目錄下找到bin目錄,並記錄該路徑,然後複製到命令視窗中,如

斷行符號,等待結果,結果如下(不要關閉命令視窗)

在項目target目錄下可以看到產生的jar

在命令視窗中輸入:clean -P test source:jar install -Dmaven.test.skip
執行配置分離,想完成這一步需要在代碼中進行配置,否則無法成功。
目錄結構如下:

pom.xml中添加:

<!-- 開發環境dubbo打包配置,不分離部署檔案 -->  <build>        <!-- 該屬性根據項目自訂,一般取值項目的artifactId -->        <finalName>ticketapply-schedule</finalName>         <resources>            <resource>                <directory>src/main/resources</directory>                <filtering>true</filtering>                <excludes>                    <exclude>assemble/*.xml</exclude>                    <exclude>conf/**/*.*</exclude>                </excludes>            </resource>        </resources>        <!--開發環境自訂打包外掛程式,不需修改 -->        <plugins>            <plugin>                <artifactId>maven-assembly-plugin</artifactId>                <configuration>                    <appendAssemblyId>true</appendAssemblyId>                    <descriptors>                        <descriptor>src/main/resources/assemble/package.xml</descriptor>                    </descriptors>                </configuration>                <executions>                    <execution>                        <id>make-assembly</id>                        <phase>package</phase>                        <goals>                            <goal>single</goal>                        </goals>                    </execution>                </executions>            </plugin>        </plugins>  </build>  <!-- 正式環境打包配置,設定檔和代碼分離 -->  <profiles>    <profile>        <!-- 該屬性不可修改,以免影響配置打包 -->        <id>test</id>        <build>        <!--自訂打包外掛程式,不需修改 -->        <plugins>            <plugin>                <artifactId>maven-assembly-plugin</artifactId>                <configuration>                    <appendAssemblyId>true</appendAssemblyId>                    <descriptors>                        <!--正式環境自訂打包描述檔案 -->                        <descriptor>src/main/resources/assemble/dubboPackage.xml</descriptor>                        <descriptor>src/main/resources/assemble/dubboConfigPackage.xml</descriptor>                    </descriptors>                </configuration>                <executions>                    <execution>                        <id>make-assembly</id>                        <phase>package</phase>                        <goals>                            <goal>single</goal>                        </goals>                    </execution>                </executions>             </plugin>         </plugins>      </build>    </profile>  </profiles>

dubboConfigPackage.xml

<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">    <id>dubboConfig</id>    <formats>        <format>zip</format>    </formats>    <includeBaseDirectory>false</includeBaseDirectory>    <fileSets>        <fileSet>            <directory>src/main/resources/conf</directory>            <outputDirectory>dubboConfig</outputDirectory>            <includes>                <include>**/*.properties</include>            </includes>        </fileSet>    </fileSets></assembly>

dubboPackage.xml

<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">    <id>package</id>    <formats>        <format>zip</format>    </formats>    <includeBaseDirectory>false</includeBaseDirectory>    <fileSets>        <fileSet>            <directory>src/main/resources/conf</directory>            <outputDirectory>conf</outputDirectory>            <excludes>                <exclude>**/*.properties</exclude>            </excludes>        </fileSet>    </fileSets>    <dependencySets>          <dependencySet>             <useProjectArtifact>true</useProjectArtifact>              <outputDirectory>lib</outputDirectory>            <!-- 將scope為runtime的依賴包打包到lib目錄下。 -->              <scope>runtime</scope>          </dependencySet>      </dependencySets>  </assembly>

package.xml

<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">    <id>package</id>    <formats>        <format>zip</format>    </formats>    <includeBaseDirectory>false</includeBaseDirectory>    <fileSets>        <fileSet>            <directory>src/main/resources/conf</directory>            <outputDirectory>conf</outputDirectory>        </fileSet>    </fileSets>    <dependencySets>          <dependencySet>             <useProjectArtifact>true</useProjectArtifact>              <outputDirectory>lib</outputDirectory>             <scope>runtime</scope>          </dependencySet>      </dependencySets>  </assembly>

命令視窗中輸入命令並執行


target目錄下會多出幾個檔案

dubboConfig是所有設定檔,package是spring檔案+設定檔+lib,sources是源碼

maven打包以及配置分離

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.