Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve module-info.java compile error in Jdk9/java-9

I am trying to run below code using jdk-9 but facing problem when compile using command

Command

 javac -d mods .\module-info.java com\nirav\modi\Test.java

Error

.\module-info.java:1: error: class, interface, or enum expected
module module1 { }
^
1 error

module-info.java

module module1 { 

}

Test.java

package com.nirav.modi;

class Test {

    public static void main(String args[]){

        System.out.println("Hello Modular...");

    }

}

package structure is like below

module1\module-info.java
module1\com\nirav\modi\Test.java

JDK Version

java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+153)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+153, mixed mode)
like image 874
NIrav Modi Avatar asked Jan 25 '17 10:01

NIrav Modi


People also ask

Which is correct about module system in Java 9?

Java Module System is a major change in Java 9 version. Java added this feature to collect Java packages and code into a single unit called module. In earlier versions of Java, there was no concept of module to create modular Java applications, that why size of application increased and difficult to move around.

What is module info in Java?

module-info. java file. It declares the dependencies within the module system and allows the compiler and the runtime to police the boundaries/access violations between the modules in your application.

Where is Java module path?

$JAVA_HOME/jmods is the directory containing java. base. jmod and the other standard and JDK modules. The directory mlib on the module path contains the artifact for module com.

Why use Java modules?

Modules have taken so long because it makes fundamental changes to the way Java has worked since 1.0, and allows Java to move forward. It also allows Java to maintain compatibility while getting rid of legacy baggage (anyone still using RMI and Corba?).


2 Answers

Per the Jigsaw Issues List, a module name cannot end with a number. The purpose is to discourage authors from encoding version numbers in module names.

like image 169
Jason Avatar answered Oct 12 '22 23:10

Jason


JSR 376 is not final yet and there are several topics still under discussion. The latest proposal on the #VersionsInModuleNames topic is here:

http://mail.openjdk.java.net/pipermail/jpms-spec-experts/2017-March/000659.html

like image 37
Alan Bateman Avatar answered Oct 12 '22 23:10

Alan Bateman