简体   繁体   中英

mvn command line java compiler version is mistaken

I have jdk8 and 9 installed. 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.

$ 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:

<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. 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.

But that is only a stop-gap. The real solution is to convert your code so that id doesn't depend on internal classes. 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.


There is nothing you can do with your POM file to fix this. Those classes are (probably) no longer present in the "rt.jar" file where the java compiler and runtime are looking for them.


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. Or something like that. The reboot probably wasn't necessary. Logging out and logging in again would probably have been sufficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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