Syntax error on token module interface expected

JDK 9 module-info.java handling #75 Comments Having a module-info.java in the source set leads to unexpected format exceptions starting with Skip module-info.java although it ends with .java Line Main.java :118 already skips non-Java files. Could easily be handled here. Support module-info.java syntax and reformat it as well. The text was updated successfully, but these […]

Содержание

  1. JDK 9 module-info.java handling #75
  2. Comments
  3. Syntax error on token «module», module expected» error
  4. ошибка в файле module-info.java в проекте javafx
  5. 1 ответ

JDK 9 module-info.java handling #75

Having a module-info.java in the source set leads to unexpected format exceptions starting with

Skip module-info.java although it ends with .java Line Main.java :118 already skips non-Java files. Could easily be handled here.

Support module-info.java syntax and reformat it as well.

The text was updated successfully, but these errors were encountered:

I’d prefer (2), but I’m also not sure what the timeline is for ecj’s java 9 support.

I prefer (2) as well, but (1) could serve as an interim solution, until ECJ supports Java 9.

Latest module syntax with layout example can be found here: http://cr.openjdk.java.net/

Any news on ecj’s java 9 support? The com.google.errorprone:javac:9-dev-r3297-1-shaded does not contain it, I guess.

We migrated from ecj to javac. javac has JDK 9 support, but I’m not sure if the version the formatter is using is new enough.

But it is missing the -shaded suffix: 9-dev-r3297-1-shaded

Although the file size suggests it does include all dependencies. but org.openjdk.tools.javac.**.* types are missing.

Seems like the update of javac would solve this problem, if -source 9 could be specified:

I added initial support for this in c31bb19. If anyone’s interested in trying it out, please report any issues you find — we don’t have a huge corpus of module-info s to test against yet.

I’ll cut a new release soon that includes that change unless any issues turn up.

All branches of the JLS module production are hit by the example M1 input/output pair:

I’ll cut a new release soon that includes that change unless any issues turn up.

Great news! (With tiny chance seeing #106 included as well?)

Also all 30 module-info.java files in https://github.com/AdoptOpenJDK/jdk9-jigsaw were formatted successfully.

Generated patch looks ok

While running against all 350 module descriptors found in an OpenJDK mirror, I found something in openjdk-jdk9langtoolstestjdkjavadocdoclettestModulesmoduletagsmodule-info.java :

Looks a like file to test the «(one of)» rule from the requires production.

Here is the error message, with some more invalid(?) module files:

Источник

Syntax error on token «module», module expected» error

  • Welcome to CodeRanch!

    The file needs to be named module-info.java.

  • Stephan van Hulst wrote: Welcome to CodeRanch!

    The file needs to be named module-info.java.

  • Welcome to CodeRanch!

  • What does your directory structure look like?
  • What folder is your module-info.java file in?
  • What Java version are you using?
  • What are you using to build the application?
  • Where are you seeing the error message?
  • module-info.java
    Looks like this

    module trigger
    <
    requires java.desktop;
    requires java.sql;
    >

    I am using jdk 1.8 version
    I am building small program using java swing.

    Please help me I am facing issue

    Syntax error or token «module», interface expected.
    The project cannot be built untill build path errors resolved

    Источник

    ошибка в файле module-info.java в проекте javafx

    Я уже некоторое время использую javaFX, но день назад, когда я создал новый проект, я заметил, что в пакете по умолчанию автоматически создается новый файл с именем (module-info.java), и я даже не могу удалите это.

    Там написан следующий код:

    К сожалению, во всех строках есть ошибки

    1-я строка: Синтаксическая ошибка токена «модуль», ожидается интерфейс

    2-я строка: Синтаксическая ошибка токена «.», Ожидается

    3-я строка: ** Несколько маркеров в этой строке

    1 ответ

    Файл module-info.java выглядит довольно типично для модульных проектов Java (Java 9+). Обычно требуется javafx.controls и открыть ваше приложение (здесь фактически названное «application») для javafx. Я думаю, что это последнее утверждение относится к модулю javafx, который должен иметь возможность заглядывать в модуль, который имеет точку входа для программы.

    Но расположение файла мне кажется подозрительным. Я не разбираюсь во всех сложностях, но я думаю, что файл лучше разместить непосредственно в каталоге / src, а не в пакете по умолчанию. Обычно файл module-info.java является верхним уровнем папки файлов, а исходный код программы — дочерней папкой.

    Другими словами, файл module-info.java и файл пакета / application должны находиться в одной папке. По крайней мере, так все устроено в моих программах javafx и модульных программах Java.

    РЕДАКТИРОВАТЬ: я заметил, что в вашем пути сборки указан Java 1.5! Эта Java не поддерживает модули. Модули были введены в Java 9.

    Источник

    Index: session-2-jlink/02_JMod/src/org.astro/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-2-jlink/02_JMod/src/org.astro/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-2-jlink/02_JMod/src/org.astro/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  exports org.astro;
    +}
    Index: session-2-jlink/01_JLink/src/org.astro/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-2-jlink/01_JLink/src/org.astro/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-2-jlink/01_JLink/src/org.astro/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  exports org.astro;
    +}
    Index: session-2-jlink/02_JMod/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-2-jlink/02_JMod/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-2-jlink/02_JMod/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module com.greetings { 
    -	requires org.astro;
    -}
     No newline at end of file
    +module com.greetings {
    +  requires org.astro;
    +}
    Index: session-2-jlink/01_JLink/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-2-jlink/01_JLink/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-2-jlink/01_JLink/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module com.greetings { 
    -	requires org.astro;
    -}
     No newline at end of file
    +module com.greetings {
    +  requires org.astro;
    +}
    Index: session-1-jigsaw-intro/06_Services/src/com.socket/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/06_Services/src/com.socket/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/06_Services/src/com.socket/module-info.java	(revision )
    @@ -1,5 +1,6 @@
     module com.socket {
    -	exports com.socket;
    -	exports com.socket.spi;
    -	uses com.socket.spi.NetworkSocketProvider;
    -}
     No newline at end of file
    +  exports com.socket;
    +  exports com.socket.spi;
    +
    +  uses com.socket.spi.NetworkSocketProvider;
    +}
    Index: session-1-jigsaw-intro/04_Packaging/src/org.astro/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/04_Packaging/src/org.astro/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/04_Packaging/src/org.astro/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  exports org.astro;
    +}
    Index: session-1-jigsaw-intro/06_Services/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/06_Services/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/06_Services/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
     module com.greetings {
    -	requires com.socket;
    -}
     No newline at end of file
    +  requires com.socket;
    +}
    Index: session-1-jigsaw-intro/04_Packaging/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/04_Packaging/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/04_Packaging/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module com.greetings { 
    -	requires org.astro;
    -}
     No newline at end of file
    +module com.greetings {
    +  requires org.astro;
    +}
    Index: session-1-jigsaw-intro/01_Greetings/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/01_Greetings/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/01_Greetings/src/com.greetings/module-info.java	(revision )
    @@ -1,1 +1,1 @@
    -module com.greetings { }
     No newline at end of file
    +module com.greetings {}
    Index: session-1-jigsaw-intro/06_Services/src/org.fastsocket/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/06_Services/src/org.fastsocket/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/06_Services/src/org.fastsocket/module-info.java	(revision )
    @@ -1,5 +1,6 @@
     module org.fastsocket {
    -	requires com.socket;
    -	provides com.socket.spi.NetworkSocketProvider
    -		with org.fastsocket.FastNetworkSocketProvider;
    -}
     No newline at end of file
    +  requires com.socket;
    +
    +  provides com.socket.spi.NetworkSocketProvider with
    +      org.fastsocket.FastNetworkSocketProvider;
    +}
    Index: session-1-jigsaw-intro/02_GreetingsWorld/src/org.astro/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/02_GreetingsWorld/src/org.astro/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/02_GreetingsWorld/src/org.astro/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  exports org.astro;
    +}
    Index: session-1-jigsaw-intro/09_Automodules/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/09_Automodules/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/09_Automodules/src/com.greetings/module-info.java	(revision )
    @@ -1,4 +1,6 @@
     module com.greetings {
    -    requires junit;
    -    exports com.greetings to junit;
    -}
     No newline at end of file
    +  requires junit;
    +
    +  exports com.greetings to
    +      junit;
    +}
    Index: session-1-jigsaw-intro/05_Missing_exports/src/org.astro/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/05_Missing_exports/src/org.astro/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/05_Missing_exports/src/org.astro/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	// exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  // exports org.astro;
    +}
    Index: session-1-jigsaw-intro/05_Missing_requires/src/org.astro/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/05_Missing_requires/src/org.astro/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/05_Missing_requires/src/org.astro/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  exports org.astro;
    +}
    Index: session-1-jigsaw-intro/02_GreetingsWorld/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/02_GreetingsWorld/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/02_GreetingsWorld/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module com.greetings { 
    -	requires org.astro;
    -}
     No newline at end of file
    +module com.greetings {
    +  requires org.astro;
    +}
    Index: session-1-jigsaw-intro/05_Missing_exports/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/05_Missing_exports/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/05_Missing_exports/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module com.greetings { 
    -	 requires org.astro;
    -}
     No newline at end of file
    +module com.greetings {
    +  requires org.astro;
    +}
    Index: session-1-jigsaw-intro/05_Missing_requires/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/05_Missing_requires/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/05_Missing_requires/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module com.greetings { 
    -	// requires org.astro;
    -}
     No newline at end of file
    +module com.greetings {
    +  // requires org.astro;
    +}
    Index: session-1-jigsaw-intro/08_ModulesExportConflict/src/org.astro/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/08_ModulesExportConflict/src/org.astro/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/08_ModulesExportConflict/src/org.astro/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  exports org.astro;
    +}
    Index: session-1-jigsaw-intro/03_MultiModuleCompilation/src/org.astro/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/03_MultiModuleCompilation/src/org.astro/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/03_MultiModuleCompilation/src/org.astro/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  exports org.astro;
    +}
    Index: session-1-jigsaw-intro/08_ModulesExportConflict/src/org.astro2/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/08_ModulesExportConflict/src/org.astro2/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/08_ModulesExportConflict/src/org.astro2/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module org.astro { 
    -	exports org.astro;
    -}
     No newline at end of file
    +module org.astro {
    +  exports org.astro;
    +}
    Index: session-1-jigsaw-intro/07_patch_module_option/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/07_patch_module_option/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/07_patch_module_option/src/com.greetings/module-info.java	(revision )
    @@ -1,2 +1,1 @@
    -module com.greetings {
    -}
     No newline at end of file
    +module com.greetings {}
    Index: session-1-jigsaw-intro/08_ModulesExportConflict/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/08_ModulesExportConflict/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/08_ModulesExportConflict/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module com.greetings { 
    -	requires org.astro;
    -}
     No newline at end of file
    +module com.greetings {
    +  requires org.astro;
    +}
    Index: session-1-jigsaw-intro/03_MultiModuleCompilation/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/03_MultiModuleCompilation/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/03_MultiModuleCompilation/src/com.greetings/module-info.java	(revision )
    @@ -1,3 +1,3 @@
    -module com.greetings { 
    -	requires org.astro;
    -}
     No newline at end of file
    +module com.greetings {
    +  requires org.astro;
    +}
    Index: session-1-jigsaw-intro/07_patch_ConcurrentHashMap/src/com.greetings/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-1-jigsaw-intro/07_patch_ConcurrentHashMap/src/com.greetings/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-1-jigsaw-intro/07_patch_ConcurrentHashMap/src/com.greetings/module-info.java	(revision )
    @@ -1,2 +1,1 @@
    -module com.greetings {
    -}
     No newline at end of file
    +module com.greetings {}
    Index: session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.rest/src/main/java/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.rest/src/main/java/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.rest/src/main/java/module-info.java	(revision )
    @@ -1,13 +1,11 @@
     module monitor.rest {
    -	requires java.xml.bind;
    -	requires java.xml.ws.annotation;
    -
    -	requires monitor.utils;
    -	requires monitor.statistics;
    -
    -	requires spark.core;
    -	requires jackson.core;
    -	requires jackson.databind;
    +  requires java.xml.bind;
    +  requires java.xml.ws.annotation;
    +  requires monitor.utils;
    +  requires monitor.statistics;
    +  requires spark.core;
    +  requires jackson.core;
    +  requires jackson.databind;
     
    -	exports monitor.rest;
    +  exports monitor.rest;
     }
    Index: session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.utils/src/main/java/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.utils/src/main/java/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.utils/src/main/java/module-info.java	(revision )
    @@ -1,4 +1,4 @@
     module monitor.utils {
    -	// requires
    -	exports monitor.utils;
    +  // requires
    +  exports monitor.utils;
     }
    Index: session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer/src/main/java/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer/src/main/java/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer/src/main/java/module-info.java	(revision )
    @@ -1,3 +1,3 @@
     module monitor.observer {
    -	exports monitor.observer;
    +  exports monitor.observer;
     }
    Index: session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.statistics/src/main/java/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.statistics/src/main/java/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.statistics/src/main/java/module-info.java	(revision )
    @@ -1,4 +1,5 @@
     module monitor.statistics {
    -	requires monitor.observer;
    -	exports monitor.statistics;
    +  requires monitor.observer;
    +
    +  exports monitor.statistics;
     }
    Index: session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer.beta/src/main/java/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer.beta/src/main/java/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer.beta/src/main/java/module-info.java	(revision )
    @@ -1,4 +1,5 @@
     module monitor.observer.beta {
    -	requires monitor.observer;
    -	exports monitor.observer.beta;
    +  requires monitor.observer;
    +
    +  exports monitor.observer.beta;
     }
    Index: session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer.alpha/src/main/java/module-info.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer.alpha/src/main/java/module-info.java	(revision 46cb9e190b44d0d8aa4f2f4544ebc41251939c52)
    +++ session-3-refactoring-migration/04_ServiceMonitor_modularisation_to_java_9/monitor.observer.alpha/src/main/java/module-info.java	(revision )
    @@ -1,4 +1,5 @@
     module monitor.observer.alpha {
    -	requires monitor.observer;
    -	exports monitor.observer.alpha;
    +  requires monitor.observer;
    +
    +  exports monitor.observer.alpha;
     }
    


    posted 2 years ago

    • Mark post as helpful


    • send pies

      Number of slices to send:

      Optional ‘thank-you’ note:



    • Quote
    • Report post to moderator

    Can anyone teach me how to resolve «Syntax error on token «module», module expected» error?

    Java used is already jdk13.0.1 yet my eclipse is unable to resolve the «module» keyword in package-info.java.

    Question1.PNG

    [Thumbnail for Question1.PNG]

    Saloon Keeper

    Posts: 14713


    posted 2 years ago


    • Likes 1
    • Mark post as helpful


    • send pies

      Number of slices to send:

      Optional ‘thank-you’ note:



    • Quote
    • Report post to moderator

    Welcome to CodeRanch!

    The file needs to be named

    module-info.java

    .

    Darack Chowansky

    Greenhorn

    Posts: 10


    posted 2 years ago

    • Mark post as helpful


    • send pies

      Number of slices to send:

      Optional ‘thank-you’ note:



    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:Welcome to CodeRanch!

    The file needs to be named

    module-info.java

    .

    Thank you!

    Sorry for such an elementary mistake.

    Marshal

    Posts: 77299


    posted 2 years ago

    • Mark post as helpful


    • send pies

      Number of slices to send:

      Optional ‘thank-you’ note:



    • Quote
    • Report post to moderator

    There is no need to be sorry.


    posted 1 year ago

    • Mark post as helpful


    • send pies

      Number of slices to send:

      Optional ‘thank-you’ note:



    • Quote
    • Report post to moderator

    My file name is module-info.java. still I have this error

    Stephan van Hulst

    Saloon Keeper

    Posts: 14713


    posted 1 year ago

    • Mark post as helpful


    • send pies

      Number of slices to send:

      Optional ‘thank-you’ note:



    • Quote
    • Report post to moderator

    Welcome to CodeRanch!

  • What does your directory structure look like?
  • What folder is your module-info.java file in?
  • What Java version are you using?
  • What are you using to build the application?
  • Where are you seeing the error message?
  • Tejaswini Halakate

    Greenhorn

    Posts: 2


    posted 1 year ago

    • Mark post as helpful


    • send pies

      Number of slices to send:

      Optional ‘thank-you’ note:



    • Quote
    • Report post to moderator

    module-info.java

    Looks like this

    module trigger

    {

    requires java.desktop;

    requires java.sql;

    }

    I am using jdk 1.8 version

    I am building small program using java swing.

    Please help me I am facing issue

    Syntax error or token «module», interface expected.

    The project cannot be built untill build path errors resolved

    Stephan van Hulst

    Saloon Keeper

    Posts: 14713


    posted 1 year ago

    • Mark post as helpful


    • send pies

      Number of slices to send:

      Optional ‘thank-you’ note:



    • Quote
    • Report post to moderator

    Modules were added in Java 9. You need to update your JDK. I recommend you use Java 11.

    jQuery in Action, 3rd edition

    Я уже некоторое время использую javaFX, но день назад, когда я создал новый проект, я заметил, что в пакете по умолчанию автоматически создается новый файл с именем (module-info.java), и я даже не могу удалите это!!.

    enter image description here

    Там написан следующий код:

    module prog0 {
        requires javafx.controls;
        
        opens application to javafx.graphics, javafx.fxml;
    }
    

    К сожалению, во всех строках есть ошибки

    1-я строка: Синтаксическая ошибка токена «модуль», ожидается интерфейс

    2-я строка: Синтаксическая ошибка токена «.», Ожидается

    3-я строка: ** Несколько маркеров в этой строке

    - Syntax error on token "to", = 
     expected
    
    - Syntax error on token ".", , 
     expected
    
    - Syntax error on token "to", = 
     expected
    
    - Syntax error on token ".", , 
     expected**
    

    Используемые библиотеки: введите описание изображения здесь

    1 ответ

    Лучший ответ

    Файл module-info.java выглядит довольно типично для модульных проектов Java (Java 9+). Обычно требуется javafx.controls и открыть ваше приложение (здесь фактически названное «application») для javafx. Я думаю, что это последнее утверждение относится к модулю javafx, который должен иметь возможность заглядывать в модуль, который имеет точку входа для программы.

    Но расположение файла мне кажется подозрительным. Я не разбираюсь во всех сложностях, но я думаю, что файл лучше разместить непосредственно в каталоге / src, а не в пакете по умолчанию. Обычно файл module-info.java является верхним уровнем папки файлов, а исходный код программы — дочерней папкой.

    Другими словами, файл module-info.java и файл пакета / application должны находиться в одной папке. По крайней мере, так все устроено в моих программах javafx и модульных программах Java.

    РЕДАКТИРОВАТЬ: я заметил, что в вашем пути сборки указан Java 1.5! Эта Java не поддерживает модули. Модули были введены в Java 9.


    1

    Phil Freihofner
    5 Авг 2021 в 00:34

    Понравилась статья? Поделить с друзьями:
  • Syntax error on token expected syntax error on token expected after this token
  • Syntax error on token expected after this token java 1610612967
  • Syntax error on token else delete this token
  • Syntax error on token close identifier expected after this token
  • Syntax error on token class char expected