简体   繁体   English

mvn命令行Java编译器版本错误

[英]mvn command line java compiler version is mistaken

I have jdk8 and 9 installed. 我安装了jdk8和9。 And in the effective pom.xml I can see the compiler plugin is assigned to 1.8, however mvn clean install prints error a sun class is missing, making me believe it still uses jdk9. 在有效的pom.xml中,我可以看到编译器插件已分配给1.8,但是mvn clean install打印错误缺少sun类,这使我相信它仍然使用jdk9。

$ mvn -version
Maven home: D:\Java\apache-maven-3.2.5
Java version: 9, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-9

pom.xml: pom.xml:

<plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <executions>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
              <encoding>UTF-8</encoding>
            </configuration>
          </execution>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
              <encoding>UTF-8</encoding>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>

You have an edge case. 你有一个极端的情况。

You (presumably) have some code that was originally developed for Java 8 (or earlier) that depends on an internal JRE class. 您(大概)拥有一些最初为Java 8(或更早版本)开发的代码,这些代码依赖于内部JRE类。 Code is not supposed to do that . 代码不应该这样做

What has apparently happened is that the internal class has been removed or replaced. 显然发生的是内部类已被删除或替换。

The only way you are going to be able to compile this code is by downloading and installing a genuine Java 8 JDK and setting your $PATH to refer to it before running Maven. 能够编译此代码的唯一方法是,在运行Maven之前,下载并安装一个正版Java 8 JDK并设置$PATH使其引用它。

But that is only a stop-gap. 但这只是一个权宜之计。 The real solution is to convert your code so that id doesn't depend on internal classes. 真正的解决方案是转换代码,以使id不依赖于内部类。 You are going to have to do that eventually anyway. 无论如何,您最终都必须这样做。 So may as well do it now ... and avoid the hassle of a special Java 8 setup to build your code. 因此,现在就做吧……并避免使用特殊的Java 8设置来构建代码的麻烦。


There is nothing you can do with your POM file to fix this. 您无法使用POM文件来解决此问题。 Those classes are (probably) no longer present in the "rt.jar" file where the java compiler and runtime are looking for them. 这些类(可能)不再存在于Java编译器和运行时正在寻找它们的“ rt.jar”文件中。


I finally got this work again! 我终于又得到了这份工作! After rebooting os. 重启操作系统后。

What probably happened is that you changed a PATH setting in a ".rc" file but did not restart your shell or re-source the file. 可能发生的情况是,您在“ .rc”文件中更改了PATH设置,但没有重新启动Shell或重新获得该文件的资源。 Or something like that. 或类似的东西。 The reboot probably wasn't necessary. 可能不需要重新启动。 Logging out and logging in again would probably have been sufficient. 注销并再次登录就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM