若是在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
<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
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就进行打包了生命周期