在maven项目中考虑以下代码:
import org.w3c.dom.css.CSSStyleDeclaration;
public class Test {
public static void main(String[] args) {
CSSStyleDeclaration styleDeclaration = null;
}
}
pom.xml
包含maven-compiler-plugin
插件的地方
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.serce.jdk10mvntest</groupId>
<artifactId>jdk10mvntest</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
可以使用maven正确编译该项目。但是,当使用IntelliJ和JDK10 SDK进行编译时,会出现Error:(1, 27) java: package org.w3c.dom.css does not exist
错误。如果将源更改为<source>10</source>
,该错误将消失。我希望问题可能与jigsaw有关,但是我不能使用--add-modules ...
,因为javac
出现了option --add-modules not allowed with target 1.8
错误。
是否有任何变通办法使我可以将IntelliJ与JDK10 SDK以及1.8
源和目标一起使用来编译此代码?
IntelliJ:2018.2
Java:Java HotSpot(TM)64位服务器VM 18.3(内部版本10.0.1 + 10,混合模式)
答案 0 :(得分:6)