Eclipse Oxygen Run Java9 Jigsaw Application

时间:2017-10-20 05:50:39

标签: eclipse java-9 jigsaw

我开始学习使用java9 Jigsaw的新功能。

我遵循this tutorial并设法创建一个包含两个模块和外部模块依赖项的项目。 (我发布下面的pom文件代码以给出产品结构的概念)

现在我想在Eclipse Oxygen中导入我的maven项目(带有Java9插件支持),以便在Eclipse IDE中运行和调试项目。

我使用Oxygen.1a并且我为Oxygen 4.7安装了Java 9支持

我使用“Import Existing Maven project”,然后选择root pom.xml。

Everithing工作得很好我有我的项目导入其中两个被认为是Java项目(jsaw-date-cli和jigsaw-date-server),而根模块被认为是一个简单的m2项目。

现在我尝试使用常见的Ran作为Java Appliocation从eclipse运行jsaw-date-cli Main“但我已经修改了:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module jigsaw.date.cli not found

如何配置项目以使cli项目自己的模块在运行时可用? 我打开正确导入外部模块的构建路径属性!

我尝试在“RunConfiguration”中添加

来设置模块
/maven-build/target/modules 

作为ModulePath条目但结果相同。

我还尝试添加VM命令行参数:

--module-path  ${workspace_loc:maven-build}/target/modules/

但错误仍然存​​在。

我可以使用

从命令行运行项目
java -jar --module-path target/modules -m jigsaw.date.cli

但我想从eclipse运行并调试它!

在poms.xml文件下面:

root 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>com.javacodegeeks</groupId>
        <artifactId>jigsaw-date</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>jigsaw-date-cli</artifactId>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.javacodegeeks</groupId>
                <artifactId>jigsaw-date-service</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.javacodegeeks</groupId>
            <artifactId>jigsaw-date-service</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <outputDirectory>${project.build.directory}/../../target/modules</outputDirectory>
                    <archive>
                        <manifest>
                            <mainClass>com.javacodegeeks.jigsaw.date.cli.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/../../target/modules</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

jigsaw-cli 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>com.javacodegeeks</groupId>
        <artifactId>jigsaw-date</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>jigsaw-date-service</artifactId>

    <properties>
        <org.apache.commons.lang.version>3.4-module</org.apache.commons.lang.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${org.apache.commons.lang.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <outputDirectory>${project.build.directory}/../../target/modules</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/../../target/modules</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

jigsaw-service 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>com.javacodegeeks</groupId>
        <artifactId>jigsaw-date</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>jigsaw-date-service</artifactId>

    <properties>
        <org.apache.commons.lang.version>3.4-module</org.apache.commons.lang.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${org.apache.commons.lang.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <outputDirectory>${project.build.directory}/../../target/modules</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/../../target/modules</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

1 个答案:

答案 0 :(得分:0)

我终于设法使用eclipse运行项目并使用调试器,无需删除或添加任何插件。

我只是在运行配置中添加广告VM argument

--module-path  ${workspace_loc:maven-build}/target/modules/ -m jigsaw.date.cli/com.javacodegeeks.jigsaw.date.cli.Main