在Eclipse Oxygen 4.7中导入Java-9-Jigsaw-Maven-Project无法正常工作 [英] Import of a Java-9-Jigsaw-Maven-Project in Eclipse Oxygen 4.7 does not work

查看:99
本文介绍了在Eclipse Oxygen 4.7中导入Java-9-Jigsaw-Maven-Project无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用:

  • JDK 9 build 9-ea + 172
  • Maven 3.5.0
  • Eclipse Oxygen 4.7 RC3版本 从2017-05-31开始4.7.0.I20170531-2000
  • Eclipse插件:
    • 具有针对氧气开发流1.1.1.v20170526-0728_BETA_JAVA9的Java 9支持(BETA)的Eclipse JDT(Java开发工具)补丁程序
    • m2e-用于Eclipse的Maven集成(包括孵化 组件),1.8.0.20170516-2043
    • JDK 9 build 9-ea+172
    • Maven 3.5.0
    • Eclipse Oxygen 4.7 RC3 Version 4.7.0.I20170531-2000 from 2017-05-31
    • Eclipse-Plugins:
      • Eclipse JDT (Java Development Tools) Patch with Java 9 support (BETA) for Oxygen development stream, 1.1.1.v20170526-0728_BETA_JAVA9
      • m2e - Maven Integration for Eclipse (includes Incubating components), 1.8.0.20170516-2043

      创建一个新的Jigsaw-Maven-Project:

      mkdir proj1\a\src\main\java\a\a
      cd proj1
      

      在目录proj1中的文件pom.xml:

      In directory proj1 the file pom.xml:

      <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>test</groupId>
        <artifactId>Proj1</artifactId>
        <version>1.0</version>
        <packaging>pom</packaging>
        <modules>
          <module>a</module>
        </modules>
        <build>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.6.1</version>
              <configuration>
                <source>9</source>
                <target>9</target>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </project>
      

      在目录proj1\a中的文件pom.xml:

      In directory proj1\a the file pom.xml:

      <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>test</groupId>
          <artifactId>Proj1</artifactId>
          <version>1.0</version>
        </parent>
        <artifactId>a</artifactId>
        <packaging>jar</packaging>
        <build>
          <sourceDirectory>src/main/java/a</sourceDirectory>
        </build>
      </project>
      

      在目录proj1\a\src\main\java\a中的文件module-info.java:

      In directory proj1\a\src\main\java\a the file module-info.java:

      module a { }
      

      在目录proj1\a\src\main\java\a\a中的文件App.java:

      In directory proj1\a\src\main\java\a\a the file App.java:

      package a;
      
      public class App {
         public static void main( String[] args ) {
            System.out.println( "CLASSPATH:           " + System.getProperty( "java.class.path" ) );
            System.out.println( "Class / Modul:       " + App.class.getSimpleName() + " from " + App.class.getModule() );
            java.lang.ModuleLayer lr = App.class.getModule().getLayer();
            if( lr != null ) {
               System.out.println( "Layer.Configuration: " + lr.configuration() );
            } else {
               System.out.println( "Error:               ModuleLayer is null" );
            }
         }
      }
      

      在命令行上运行项目:

      cd proj1
      mvn clean package
      java -p a\target\a-1.0.jar -m a/a.App  
      

      ->

      CLASSPATH:
      Class / Modul:       App from module a
      Layer.Configuration: java..., ...  
      

      ->
      完美运行,没有错误(CLASSPATH为空,getModule()中的名称正确,并且ModuleLayer有效).

      -->
      Works perfect without error (CLASSPATH is empty, name from getModule() is correct, and ModuleLayer is valid).

      在IntelliJ IDEA 2017.2 EAP中打开项目
      ->
      完美运行,没有错误(CLASSPATH为空,getModule()中的名称正确,并且ModuleLayer有效).

      Opening the project in IntelliJ IDEA 2017.2 EAP
      -->
      Works perfect without error (CLASSPATH is empty, name from getModule() is correct, and ModuleLayer is valid).

      在Eclipse Oxygen 4.7 RC3中导入项目:
      ->

      CLASSPATH:           ...\proj1\a\target\classes
      Class / Modul:       App from unnamed module @68f7aae2
      Error:               ModuleLayer is null
      

      ->
      这三行都是错误的.

      -->
      All three lines are wrong.

      如何避免出现此错误?

      推荐答案

      这是Eclipse Oxygen 4.7 RC3中的错误,请参见:
      Eclipse错误517777:在Eclipse Oxygen 4.7中运行Java 9应用程序未设置模块路径 ( https://bugs.eclipse.org/bugs/show_bug.cgi?id = 517777 )

      Eclipse错误514760:运行配置应支持模块概念 ( https://bugs.eclipse.org/bugs/show_bug.cgi?id = 514760 )

      This is a bug in Eclipse Oxygen 4.7 RC3, see:
      Eclipse Bug 517777: Running a Java 9 application in Eclipse Oxygen 4.7 does not set the module path (https://bugs.eclipse.org/bugs/show_bug.cgi?id=517777)
      and
      Eclipse Bug 514760: Run configuration should support notion of modules (https://bugs.eclipse.org/bugs/show_bug.cgi?id=514760)

      这篇关于在Eclipse Oxygen 4.7中导入Java-9-Jigsaw-Maven-Project无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆