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包可以在其他项目中引用。