Maven引用自定义jar包,并且在打包时包含自定义jar包
1,IDEA或eclipse开发工具使用maven管理项目时,如何引用自定义的jar包呢?
传统项目直接把jar包丢在lib下就ok了,maven项目的话需要在pom文件中配置一下。
第一步:在项目根目录下创建lib文件夹;
第二步:把jar包放到lib下;
第三不:pom中加入本地依赖
<dependency>
<groupId>net.mingsoft</groupId>
<artifactId>shiro-freemarker-tags</artifactId>
<version>1.0.0</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/lib/shiro-freemarker-tags-1.0.0.jar</systemPath>
</dependency>
注意:scope必须是system,systemPath必须用${project.basedir}引用项目目录
2,直接打包,归档文件不会包含自定义jar包,如何在打成包时包含自定义jar包呢?
如果归档文件是jar包,则与plugins标签平级添加resources标签
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
</resource>
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources>
注意:**/.jar表lib文件下的所有jar后缀文件。*
如果归档文件是war包,打包插件plugin的configuration标签下要添加webResources标签
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>${project.artifactId}</warName>
<webResources>
<resource>
<directory>lib/</directory>
<targetPath>WEB-INF/lib</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputFileNameMapping>@{artifactId}@-@{baseVersion}@.@{extension}@</outputFileNameMapping>
</configuration>
</plugin>