【问题标题】:Maven isn't working with specifying Java JDK?Maven 不使用指定 Java JDK?
【发布时间】:2014-12-23 05:38:52
【问题描述】:

我正在尝试指定要在 Maven/IntelliJ IDEA 中使用的 Java JDK 版本。我想用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 中编译...

有什么帮助吗?

谢谢, ~静态Java

【问题讨论】:

标签: java maven intellij-idea


【解决方案1】:

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

我的设置为 Use Project JDK (1.7) 但听起来你的设置为不同的。

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

祝你好运。

【讨论】:

    猜你喜欢
    • 2011-01-31
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 2016-07-08
    • 1970-01-01
    • 2019-04-19
    相关资源
    最近更新 更多