Maven 引用项目中的jar包

0
(0)
<dependency>
    <groupId>patchca</groupId>
    <artifactId>patchca</artifactId>
    <version>0.5.0</version>
    <scope>system</scope>
    <systemPath>${pom.basedir}/src/main/webapp/WEB-INF/lib/patchca-0.5.0.jar</systemPath>
</dependency>

这样就省去了将jar包安装到本地maven仓库的麻烦~只要保证需要用的jar包在lib下面就可以了。

这么做的目的是为了使用mvn:compile去编译项目,有些开发工具会在代码被修改后自动编译,因为在ide的环境中web项目的lib目录可能已经被添加为了classpath,但是在maven执行编译的时候,这个lib目录下的jar包是不会自动加入到classpath的,这里使用的不是加入classpath的方式,而是直接用maven指定jar文件的方式,更加方面,可移植性更高。

注意,这里使用的是pom.basedir而不直接写basedir就是为了在执行maven命令的时候,避免因为manve引入了项目中的jar发出类似于下面的警告。

[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.fengyunhe:sptemplate:war:1.0-SNAPSHOT
[WARNING] ‘dependencies.dependency.systemPath’ for patchca:patchca:jar should not point at files within the project directory, ${basedir}/src/main/webapp/WEB-INF/lib/patchca-0.5.0.jar will be unresolvable by dependent projects @ line 356, column 25
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]

这篇文章有用吗?

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位评论此文章。

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据