maven 將本地的jar打包進tar.gz

1. 添加一個本地依賴

若是在maven項目中加入本身的jar,pom.xml中須要這樣寫:apache

<dependency>
			<groupId>StoreClientTest</groupId>
			<artifactId>StoreClientTest</artifactId>
			<version>0.0.1-SNAPSHOT</version>
	        <scope>system</scope> 
        	<systemPath>${project.basedir}/src/main/resources/lib/store-service.jar</systemPath>
</dependency>

這個store-service.jar就是咱們本身寫的jar,而${projuce.basedir} 是maven內置屬性,指的是項目的根目錄,這樣將本地jar包放到resources/lib下面maven就能夠找到了app

2.加入assembly打包插件

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
			<!--綁定到package生命週期階段上 --> 
                        <phase>package</phase>
                        <goals>
			    <!--綁定到package生命週期階段上 -->  
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <finalName>${project.artifactId}-${project.version}</finalName>
                    <descriptors>
			<!-- 描述文件路徑 -->
                        <descriptor>src/main/package/package.xml</descriptor>
                    </descriptors>
                </configuration>
</plugin>

能夠看到配置mvn打包的文件是package.xmlmaven

3. 配置將本地jar路徑加入打包範圍

package.xml:spa

<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>tar.gz</format>
	</formats>
	<includeBaseDirectory>true</includeBaseDirectory>
	<fileSets>
		<fileSet>
			<directory>bin</directory>
			<outputDirectory>bin</outputDirectory>
		</fileSet>
		<fileSet>
			<directory>src/main/resources</directory>
			<outputDirectory>conf</outputDirectory>
		</fileSet>
		<fileSet>
			<directory>src/main/resources/lib</directory>
			<outputDirectory>lib</outputDirectory>
		</fileSet>
	</fileSets>
	<dependencySets>
		<dependencySet>
			<outputDirectory>lib</outputDirectory>
			<scope>runtime</scope>
		</dependencySet>
	</dependencySets>
</assembly>

咱們配置了fileSet將項目中的bin目錄打包到輸出目錄的bin下,將項目中src/main/resources中的文件打包到輸出目錄的conf下插件

重點是這裏:code

<fileSet>
            <directory>src/main/resources/lib</directory>
            <outputDirectory>lib</outputDirectory>
</fileSet>
orm

將咱們本身加入的resouces/lib下的ja打包到了輸出目錄lib下xml

而後進入到pom.xml所在項目路徑運行 mvn package就進行打包了生命週期

相關文章
相關標籤/搜索