1.依賴本地jar包:system scope
<dependencies>裡添加
<dependency>
<groupId>norma-log-parser</groupId>
<artifactId>norma-log-parser</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/libs/norma-log-parser-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
2.把依賴jar包添加到新生成的jar的libs目錄裡
<build>裡添加
<resources>
<resource>
<targetPath>libs</targetPath>
<directory>libs</directory>
<includes>
<include>**/norma-log-parser-1.0.0-SNAPSHOT.jar</include>
</includes>
</resource>
</resources>
3. 把所有依賴包打進新生成的jar,在<build>裡添加
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>norma-log-parser_contain-with-dependencies</finalName>
</configuration>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<artifactId>maven-assembly-plugin</artifactId>-->
<!--<configuration>-->
<!--<descriptorRefs>-->
<!--<descriptorRef>jar-with-dependencies</descriptorRef>-->
<!--</descriptorRefs>-->
<!--</configuration>-->
<!--</plugin>-->
</plugins>
4.jar包添加到本地倉庫:使用依賴的時候可以去除system scope
mvn install:install-file -Dfile=norma-log-parser-1.0.0-SNAPSHOT.jar -DgroupId=norma-log-parser -DartifactId=
norma-log-parser -Dversion=1.0 -Dpackaging=jar
5.指定java使用版本:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
生成添加依賴包的jar比較好的方式:
1.如果依賴本地jar,先把jar添加到本地倉庫,如上4中。
2.把依賴的包打入新jar中,如上3中。(不需要2中添加resource)
編譯出來的jar包可以在其他項目中引用。