前言
在编译Java代码时,总是会遇到各种各样的错误,防不胜防。这些问题还总是重复出现,奈何自己记性差,每次修改完,下次都忘了是怎么修改的了。下次出问题的时候,又得将网上的相关文档浏览一遍,才能找到适合自己的解决方案,所以索性在这里记录个文档,下次出问题可以直接在这里找到解决方案。方便快捷,持续更新!
问题汇总
重复依赖问题
问题描述
Some problems were encountered while building the effective model for xxx
'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.belerweb:pinyin4j:jar -> duplicate declaration of version 2.5.0 @ line 206, column 15
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.
出错原因
在同一个 pom.xml 文件中同时依赖了两个相同的依赖(比如:pinyin4j) ,去掉一个即可
致命错误: 在类路径或引导类路径中找不到程序包 java.lang
问题描述
致命错误: 在类路径或引导类路径中找不到程序包 java.lang
这个问题可能有多种原因导致:
出错原因1:
配置问题:pom.xml中以下标签中的
<compilerArguments>
<verbose />
<bootclasspath>${java.home}/jre/lib/rt.jar;${java.home}/jre/lib/jce.jar</bootclasspath>
</compilerArguments>
出错原因2:
环境问题: 我的报错信息中有一条错误信息为:
[类文件的搜索路径: /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/lib/rt.jar…………
实际上我的项目中的JDK版本为:
<properties>
<package.environment>local</package.environment>
<java.home>/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/jre</java.home>
</properties>
这里可以看到我的SDK是默认的Java11,然后只需要选择你需要的SDK版本,点击apply即可,重新编译即解决此问题。
多重选择提示问题
问题描述
objc[18200]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/java (0x106bcd4c0) and /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1086ae4e0). One of the two will be used. Which one is undefined.
出错原因
这个错误是JDK7的最后一个版本7u80遗留的一个错误,当然这个BUG是没有危险的,可以忽略。这个问题在JDK8的第152版本和JDK9已经修复了。
除了升级JDK版本外,可以选择忽略这个报错,步骤如下:
1、 Help —> Edit Custom Properties
2、 将idea.no.launcher=true添加到idea.properties中
3、 保存,重启idea