有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Maven没有指定JavaJDK吗?

我试图指定在Maven/IntellijIDEA中使用哪个JavaJDK版本。我想使用JDK 7,但源代码似乎总是用JDK 8编译。我做了很多事情,这是IntelliJ IDEA项目结构设置的截图:

http://i.stack.imgur.com/wabk2.png

这是我的pom。xml。如您所见,我正在使用属性和maven编译器插件

<?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.staticjava</groupId>
<artifactId>VillagerMerchants</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>

<repositories>
    <repository>
        <id>spigot-repo</id>
        <url>http://repo.md-5.net/content/groups/public/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.7.9-R0.3-SNAPSHOT</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.bukkit</groupId>
        <artifactId>craftbukkit</artifactId>
        <version>1.7.9-R0.3-SNAPSHOT</version>
    </dependency>
</dependencies>

我不知道为什么,但代码总是编译在1.8

有什么帮助吗

谢谢, ~z~ java


共 (1) 个答案

  1. # 1 楼答案

    你需要进入Settings->Project Settings->Maven->Runner并检查JRE设置

    我的设置是使用Project JDK(1.7),但听起来你的设置不同

    顺便说一句,我想您应该知道pom(1.7)中的“语言级别”与编译时使用的实际JDK设置不同。例如,您可以很好地使用JDK 1.8,但可以编译到语言级别java 7…:)

    祝你好运