如何在Eclipse中运行Java 9主类而不编辑启动配置? [英] How to run a Java 9 main class in Eclipse without editing a launch-configuration?

查看:146
本文介绍了如何在Eclipse中运行Java 9主类而不编辑启动配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行于Java 9.0.1的Eclipse Oxygen.1a版本(4.7.1a)的Maven项目中创建了一个简单的Hello World主类和module-info.java文件.

I created a simple Hello World main class and a module-info.java file within a Maven project in Eclipse Oxygen.1a Release (4.7.1a), running on Java 9.0.1.

当我尝试通过右键单击来启动主类时-以Java身份运行的应用程序 我收到错误消息:

When I try to start the main class with right-click - Run As Java Application I get the error:

启动层初始化期间发生错误
java.lang.module.FindException:找不到模块com.github.gv2011.quarry.modules.moda

Error occurred during initialization of boot layer
java.lang.module.FindException: Module com.github.gv2011.quarry.modules.moda not found

我可以从target/classes目录的命令行成功运行它:

I can successfully run it from the command line from the target/classes directory:

java -p . -m com.github.gv2011.quarry.modules.moda/com.github.gv2011.quarry.modules.moda.Hello
Hello

如果我手动编辑创建的启动配置并添加V​​M参数

If I manually edit the created launch configuration and add the VM arguments

-p target/classes
-m com.github.gv2011.quarry.modules.moda/com.github.gv2011.quarry.modules.moda.Hello

它也可以工作.

在没有手动启动配置编辑的情况下,是否有更舒适的方法从Eclipse启动主类?

Is there a more comfortable way to start main classes from Eclipse without that manual launch-configuration editing?

主类:

package com.github.gv2011.quarry.modules.moda;
public class Hello {
  public static void main(final String[] args) {
    System.out.println("Hello");
  }
}

module-java:

module-java:

module com.github.gv2011.quarry.modules.moda {
  exports com.github.gv2011.quarry.modules.moda;
}

相关问题: Eclipse-添加模块时找不到模块-info.java

Eclipse创建的启动配置(不起作用)是这样的:

The launch configuration created by Eclipse (not working) is this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
        <listEntry value="/quarry-modules-a/src/main/java/com/github/gv2011/quarry/modules/moda/Hello.java"/>
    </listAttribute>
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
        <listEntry value="1"/>
    </listAttribute>
    <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.github.gv2011.quarry.modules.moda.Hello"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="quarry-modules-a"/>
    <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
</launchConfiguration>

有效的方法是:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
        <listEntry value="/quarry-modules-a/src/main/java/com/github/gv2011/quarry/modules/moda/Hello.java"/>
    </listAttribute>
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
        <listEntry value="1"/>
    </listAttribute>
    <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.github.gv2011.quarry.modules.moda.Hello"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="quarry-modules-a"/>
    <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-p target/classes&#13;&#10;-m com.github.gv2011.quarry.modules.moda/com.github.gv2011.quarry.modules.moda.Hello"/>
</launchConfiguration>

推荐答案

此问题将在Eclipse Photon中修复(我已经使用4.8M6进行了检查).

This will be fixed in Eclipse Photon (I've checked with 4.8M6).

如果您不想等到六月,则可以从

If you don't want to wait until June, you can download the current milestone build from https://www.eclipse.org/downloads/index-developer.php

以前,根本没有在m2e中为氧气设置模块路径(在

Setting the modulepath was previously simply not implemented in m2e for Oxygen (it was implemented for Photon in https://bugs.eclipse.org/bugs/show_bug.cgi?id=529398.)

这篇关于如何在Eclipse中运行Java 9主类而不编辑启动配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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