標籤:
按住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打包以及配置分離