Eclipse oxygen Release 1a + Java 9 + maven project not working

I tried java 9 with eclipse oxygen 1a Release. As for a simple java 9 project, then this is a problem. It works. Here is a screenshot of java 9 simple program

Java 9 Without Maven in eclipse

Here is my Welcome.java. You can see that I am using the Java 9 feature in this program

package com.jdojo.intro;

public class Welcome {

    public static void main(String[] args) {

        System.out.println("Welcome to the Module System.");

        // Print the module name of the Welcome class
        Class<Welcome> cls = Welcome.class;
        Module mod = cls.getModule();
        String moduleName = mod.getName();
        System.out.format("Module Name: %s%n", moduleName);
    }
}

But I have a problem with the Maven project with Java 9. I created almost the same project with maven. Here is my pom.xml file. I also used junit 5 dependency

<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>pk.training.basit</groupId>
    <artifactId>Ch3-02-HelloWorldMaven</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Ch3-02-HelloWorldMaven</name>
    <url>http://maven.apache.org</url>

    <properties>

        <java-version>9</java-version>

        <!-- Unit testing -->
        <junit.version>4.12</junit.version>
        <junit-jupiter-engine.version>5.0.1</junit-jupiter-engine.version>
        <junit-platform-runner.version>1.0.1</junit-platform-runner.version>

        <!-- Logging -->
        <log4j.version>2.9.1</log4j.version>
        <jboss-logging.version>3.3.1.Final</jboss-logging.version>

        <junit-jupiter-engine.version>5.0.1</junit-jupiter-engine.version> 

        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
        <maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
        <exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
        <maven-failsafe-plugin.version>2.20</maven-failsafe-plugin.version>
        <maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    </properties>

    <dependencies>

        <!-- Unit Testing  -->

        <!-- JUnit Jupiter test engine implementation, only required at runtime. -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit-jupiter-engine.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>${junit-platform-runner.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Logging-->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4j.version}</version>
            <scope>compile</scope>
        </dependency>
        ......
</dependencies>

<build>
    <pluginManagement>
        <plugins>

            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-enforcer-plugin</artifactId>
                                    <versionRange>[1.0.0,)</versionRange>
                                    <goals>
                                        <goal>enforce</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
                <compilerArgument>-Xlint:all</compilerArgument>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>${exec-maven-plugin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>pk.training.basit.HelloFXApp</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${maven-failsafe-plugin.version}</version>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>${maven-javadoc-plugin.version}</version>
            <configuration>
                <additionalparam>-Xdoclint:none</additionalparam>
            </configuration>
        </plugin>
    </plugins>
</build>

The structure of the project can be seen in the screenshot. Here is my AppTest.java

package pk.training.basit;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

public class AppTest {

    @Test
    void myFirstTest() {
        assertEquals(2, 1 + 1);
    }
}

If the file is module-info.javamissing in src/main/java. Then this test case is executed. Just right click and select Run As--> Junit Test. If I Welcome.javaselect the java file that is and select Run As --> Java Application. Then I get the following output

Welcome to the Module System.
Module Name: null

. . . , null. module-info.java src/main/java/. . module-info.java.

module pk.training.basit {

}

, maven. AppTest.java. . , Welcome.java Run As --> Java Application. , . "".

Error occurred during initialization of boot layer
java.lang.module.FindException: Module pk.training.basit not found

, module-info.java. , Ch3-02-HelloWorldMaven, Configure --> Create module-info.java. . pk.training.basit Finish.

Java Error 9 Maven

, Welcome.java.

Error occurred during initialization of boot layer
java.lang.module.FindException: Module pk.training.basit not found

, AppTest.java. module-info.java

module pk.training.basit {
    exports pk.training.basit;
    //requires org.junit.jupiter.api;
}

Welcome.java. .

Error occurred during initialization of boot layer
java.lang.module.FindException: Module pk.training.basit not found

, . maven eclipse. , 1a, Maven .

java 9 GA. java 8 java 7. java 9 eclipse.ini. -vm C:\Program Files\Java\jdk-9\bin\javaw.exe

....
openFile
--launcher.appendVmargs
-vm
C:\Program Files\Java\jdk-9\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.8
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-XX:+UseG1GC
....

- . , , .

module-info.java eclipse. Java 9 multi module project. . . . module-info.java.

eclipse. . modules-info.java, .

, maven. . spring, apache .. , module.web, Java , -, module-info.java. source.service. module-info.java.

, , eclipse . , , , , eclipse .

, - , , .

.

+4

Source: https://habr.com/ru/post/1687912/


All Articles