我安装了JDK 1.8并将 JAVA_HOME 配置为 JDK 1.8 。我正在使用apache-maven-3.0.5。我创建了一个maven项目并将 maven-compiler-plugin(3.3) xmlFiles <- list.files(pattern='\\.CT$');
xmlFiles;
## [1] "CivilizationBE_DX11-6042.TXT.CT" "CivilizationBE_DX11-6122.TXT.CT"
res <- do.call(rbind,lapply(xmlFiles,function(xmlFile)
xmlToDataFrame(
xpathApply(xmlInternalTreeParse(xmlFile),'//CheatEntry'),
c('integer','character','character','character','character'),
stringsAsFactors=F
)
));
head(res); tail(res);
## ID Description LastState VariableType Address
## 1 0 "No description" 4 Bytes 0AEEE67C
## 2 1 "No description" 4 Bytes 0AEEE68C
## 3 2 "No description" 4 Bytes 0AF6E67C
## 4 3 "No description" 4 Bytes 0AF6E68C
## 5 4 "No description" 4 Bytes 0B827378
## 6 5 "No description" 4 Bytes 0B8992C8
## ID Description LastState VariableType Address
## 194 105 "No description" 4 Bytes 25E7EAC4
## 195 106 "No description" 4 Bytes 25E7EAC8
## 196 107 "No description" 4 Bytes 25E7EAD4
## 197 108 "No description" 4 Bytes 2E15F970
## 198 109 "No description" 4 Bytes FF6A673C
## 199 110 "No description" 4 Bytes FFBCA308
和<source>
配置为 1.7 。
问题是如果我使用任何Java 1.8功能,如<target>
或String.join()
,即使我将编译器级别设置为 1.7 ,它仍然可以成功编译。
我观察到的一件事是,如果我将JAVA_HOME指向JDK 1.7目录,则会导致编译错误。
但我的期望是,即使我在我的pom.xml中将编译器级别设置为1.7时JAVA_HOME指向JDK 1.8,它应该服从编译器级别(1.7)并抛出错误。
我错过了什么?
PS:当我从Eclipse IDE运行时,它使用正确的JDK(1.7)并给出错误。但是当我从命令行运行它时,我遇到了这个问题。
答案 0 :(得分:3)
你混合了两件事:
default
方法,lambdas)Stream
,Optional
,String.join
)Maven只能检查编译器级别,你正在做的是使用JDK 1.8中的库,这没关系,除非你希望代码在JDK 1.7上运行。
此外,即使java并不总是知道哪些方法/类出现在较新版本的标准库中(并非所有方法/类都标有@since
标记),所以如果你想尝试对{{1}进行补充你会得到类似的结果。
答案 1 :(得分:2)
在使用JDK 8进行编译时,更改源和目标级别不会检查您是否使用1.8 API。它只会检查语言功能。
您可以使用Animal Sniffer Maven plugin并执行API检查,如果您尝试使用1.8 API,则可以将其设置为使构建失败。