Module-info.java无法在Maven项目中编译(令牌“模块”上的语法错误,需要使用接口)

时间:2019-04-22 16:34:16

标签: eclipse maven module java-9

我正在启动一个新的maven项目,该项目将与Spring Boot一起运行(如果相关),并且编译良好。但是后来我决定开始使用Java9模块。所以我让eclipse生成了module-info.java。看起来像这样:

module birdtreemodel {
    exports mjl.familytree.birdtree;

    requires junit;
    requires spring.boot;
    requires spring.boot.autoconfigure;
    requires spring.boot.test;
    requires spring.test;
}

但是,这将导致编译错误。 Eclipse表示“令牌“模块”上的语法错误,预期接口” (并且当我执行Maven全新安装时,它会显示“编译失败:...找不到模块:junit”,对于模块spring.boot.test和spring.test也是如此)

回显%JAVA_HOME%给出C:\ Program Files \ Java \ jdk-12

mvn -version给出:

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:1
4+02:00)
Maven home: D:\Programming practice\maven\apache-maven-3.5.4\bin\..
Java version: 12, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-12
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

该项目的Maven版本的运行配置也位于jdk-12

我的pom看起来像这样:

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>mjl.familytree</groupId>
    <artifactId>birdtree-model-dao</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>birdtree-model-dao</name>
    <description>My family tree program</description>


    <repositories>
        <repository>
            <id>repository.spring.release</id>
            <name>Spring GA Repository</name>
            <url>http://repo.spring.io/release</url>
        </repository>
    </repositories>

    <properties>
        <maven.compiler.source>1.12</maven.compiler.source>
        <maven.compiler.target>1.12</maven.compiler.target>
        <maven.compiler.release>12</maven.compiler.release>
        <java.version>12</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

0 个答案:

没有答案