如何在Spring框架中:轻松获取、保存及编译源代码 - 遇到的编译问题与解决方案
最编程
2024-02-23 18:55:38
...
1、找不到jar包的问题
编译时,可以编译成功,但是会有jar包找不到的问题。
Errors occurred while build effective model from D:\worktools\Gradle\gradle_repository\caches\modules-2\files-2.1\com.alibaba\druid\1.2.6\c57198d77a31adf5bd36d35f9b12dc936b732587\druid-1.2.6.pom:
'dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${project.basedir}/lib/openjdk-1.8-tools.jar in com.alibaba:druid:1.2.6
'dependencies.dependency.systemPath' for com.sun:jconsole:jar must specify an absolute path but is ${project.basedir}/lib/openjdk-1.8-jconsole.jar in com.alibaba:druid:1.2.6
解决方案一:
根据报错信息中给出的路径找到文件,将文件中的依赖注释掉
<!--找不到以下两个jar包,将jar包的引入注释掉
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/openjdk-1.8-tools.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>jconsole</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/openjdk-1.8-jconsole.jar</systemPath>
</dependency>
-->
解决方案二:
根据错误信息中给出的缺少的jar包,如果本地有这个jar包,那么将systemPath中的路径修改为绝对路径即可。
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<!--将jar包路径修改为绝对路径-->
<systemPath>D:/worktools/jdk/jdk-11.0.11/lib/openjdk-1.8-tools.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>jconsole</artifactId>
<version>1.8</version>
<scope>system</scope>
<!--将jar包路径修改为绝对路径-->
<systemPath>D:/worktools/jdk/jdk-11.0.11/lib/openjdk-1.8-jconsole.jar</systemPath>
</dependency>
如果本地没有提示中缺少的jar包,如果必须使用该jar包,那么需要寻找jar包资源,将然后将存放jar的绝对路径写到配置文件中。如果不适用jar包中的内容,那么可以创建一个txt文件,命名为jar缺失的jar包名称,将后缀改为.jar,同样需要将jar包的绝对路径写到配置文件中。
2、JDK版本不对应的问题
本地配置的Java的环境变量的JDK版本要与spring源码要求的版本对应。不然会有一下错误:无效的源发行版:17。
我现在的最新的spring源码,使用的是jdk17。
在编译之前查看spring要求的JDK版本:查看Spring编译要使用的JDK。
注意:要修改Java的环境变量中的jdk版本,只修改项目使用JDK是无效的。
3、编译时可能出现的警告
编译时可能会有以下警告。
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
在Settings中搜过async,然后将Instrumenting agent的勾选去掉,警告就没有了。