我在Java 8 JDK上编写Java 7代码 我跑的时候
mvn clean install
显示错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project foo: Compilation failure: Compilation failure:
[ERROR] /E:/bar/XmlUtils.java:[9,44] package com.sun.xml.internal.bind.marshaller does not exist
[ERROR] /E:/bar/XmlUtils.java:[11,34] cannot find symbol
[ERROR] symbol: class CharacterEscapeHandler
[ERROR] /E:/.../FooServiceImpl.java:[106,44] package com.sun.xml.internal.bind.marshall
这是代码生成错误
CharacterEscapeHandler.class.getName()
Maven无法找到 import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler;
Maven无法找到CharacterEscapeHandle
。如何解决?
但是当我构建,打包,运行Eclipse Neon时,没问题。如何解决?
答案 0 :(得分:1)
通常,您不应使用com.sun.xml.internal包中的任何代码。这是故意失败的。以下是更多详细信息:https://bugs.java.com/bugdatabase/view_bug.do;jsessionid=1711ee4eae3ff10565fc7a212018?bug_id=6778491
答案 1 :(得分:-2)
这是临时解决方案
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>rt.jar</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<fork>true</fork>
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Maven建立成功。