Maven项目引用本地jar包依赖打包警告should not point at files within the project directory

Maven项目引用本地jar包依赖打包警告Some problems were encountered while building the effective model for com.xxx.xxx:xxx-xxx:jar should not point at files within the project directory

导入本地包WARNING警告的配置如下:
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cad</artifactId>
    <version>19.9</version>
    <scope>system</scope>
    <!-- WARNING警告点 -->
    <systemPath>${project.basedir}/lib/aspose-cad-19.9.jar</systemPath>
</dependency>
<dependency>
    <groupId>cpdetector</groupId>
    <artifactId>cpdetector</artifactId>
    <version>1.04</version>
    <scope>system</scope>
    <!-- WARNING警告点 -->
    <systemPath>${project.basedir}/lib/cpdetector-1.04.jar</systemPath>
</dependency>
警告信息:
Some problems were encountered while building the effective model for com.xxx.xxx:xxx-xxx:jar:3.3.0
'dependencies.dependency.systemPath' for com.aspose:aspose-cad:jar should not point at files within the project directory, ${project.basedir}/lib/aspose-cad-19.9.jar will be unresolvable by dependent projects @ line 177, column 25
'dependencies.dependency.systemPath' for cpdetector:cpdetector:jar should not point at files within the project directory, ${project.basedir}/lib/cpdetector-1.04.jar will be unresolvable by dependent projects @ line 185, column 25
It is highly recommended to fix these problems because they threaten the stability of your build.
For this reason, future Maven versions might no longer support building such malformed projects.

大概意思是:

在打包时com.xxx.xxx:xxx-xxx:jar:3.3.0遇到了一些问题,‘dependencies.dependency.systemPath’下的com.aspose:aspose-cad:jar不应该指向项目目录。

在177行25列${project.basedir}/lib/aspose-cad-19.9.jar将无法解析依赖。

在185行25列${project.basedir}/lib/cpdetector-1.04.jar将无法解析依赖。

强烈建议修复这些问题,因为它们威胁到构建的稳定性。

因为在未来的Maven版本可能不再支持构建这种格式错误的项目。

报了这个警告但是包都能正常打进去,网上有人说打不进去,按照网上的方式包反而打不进去了。
搜到的解决方式参见:https://blog.csdn.net/asing1elife/article/details/82732113

解决方案:

1.去掉<scope><systemPath>标签,即改为:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cad</artifactId>
    <version>19.9</version>
</dependency>
<dependency>
    <groupId>com.cpdetector</groupId>
    <artifactId>cpdetector</artifactId>
    <version>1.04</version>
</dependency>

2.使用插件导入本地jar包,这里有提供2种方式:
第一种方式,使用spring-boot-maven-plugin插件:
关键配置<argument>${project.basedir}\lib</argument>导入lib下的所有jar包

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <arguments>
            <argument>${project.basedir}\lib</argument>
        </arguments>
    </configuration>
</plugin>

第二种方式,使用maven-compiler-plugin插件:
关键配置<extdirs>${project.basedir}\lib</extdirs>导入lib下的所有jar包

<plugin>
	<artifactId>maven-compiler-plugin</artifactId>
	<configuration>
		<source>1.8</source>
		<target>1.8</target>
		<encoding>UTF-8</encoding>
		<optimize>true</optimize>
		<!-- 导入\lib下的本地jar包 -->
		<compilerArguments>
			<extdirs>${project.basedir}\lib</extdirs>
		</compilerArguments>
	</configuration>
</plugin>

优点:
1.解除了以上打包警告。
2.可以单个导入jar包,如果本地jar依赖比较多,也可以直接导入\lib目录下的所有jar包。
缺点:
1.引入了新的插件(可以忽略)。
2.待补充······

  • 8
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果在使用 Maven 引入本地 jar 包时,出现了类似 "should not point at files within the project directory" 的异常提示,这通常是因为在 `pom.xml` 文件中使用了错误的 `<systemPath>`。 为了解决这个问题,你可以尝试以下步骤: 1. 将本地 jar 包安装到本地 Maven 仓库中,使用以下命令: ``` mvn install:install-file -Dfile=<path-to-jar> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> ``` 2. 在你的 Maven 项目的 `pom.xml` 文件中添加以下依赖项: ```xml <dependency> <groupId><group-id></groupId> <artifactId><artifact-id></artifactId> <version><version></version> <scope>system</scope> <systemPath>${project.basedir}/lib/<jar-filename></systemPath> </dependency> ``` 其中,`<group-id>`、`<artifact-id>` 和 `<version>` 必须与你在之前安装 jar 包时指定的 Maven 坐标相同。`<jar-filename>` 是本地 jar 文件的文件名。 注意,这里的 `<systemPath>` 元素必须指向 `lib` 目录下的本地 jar 文件,而不是你的项目目录中的 jar 文件。因此,使用 `${project.basedir}` 变量来指向项目的基础目录,然后再将 `lib/<jar-filename>` 添加到路径中。 3. 在命令行中执行 `mvn clean install` 命令,重新打包你的 Maven 项目。 如果一切顺利,你应该能够成功引入本地 jar 包,并且在打包时不会出现 "should not point at files within the project directory" 的异常提示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值