Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

idea: too many module declarations found

I want to create hello world java 9 application and start it in intellij idea.

Now I have following structure:
enter image description here

content of inner module-info.java:

module my.module.Second {
    requires my.module.First;
}

content of outer module-info.java:

module my.module.First {
    exports my.pack;
}

But idea complains about my project:

Error:(1, 1) java: too many module declarations found

I don't understand why it happens and what really wrong. So

Question:

My question is how to force idea to accept my hello world.

P.S. From the first glance error looks obvious but I have project which I downloaded from github with the same structure but it works properly and idea doesn't complain about it:

enter image description here

like image 285
gstackoverflow Avatar asked May 24 '19 13:05

gstackoverflow


People also ask

How do I add multiple modules in IntelliJ?

From the main menu, select File | New | Module from Existing Sources. In the dialog that opens, specify the path the . iml file of the module that you want to import, and click Open. By doing so, you are attaching another module to the project without physically moving any files.

What is an .IML file?

IML is a module file created by IntelliJ IDEA, an IDE used to develop Java applications. It stores information about a development module, which may be a Java, Plugin, Android, or Maven component; saves the module paths, dependencies, and other settings.


1 Answers

According to Oracle Jar file specification

A modular JAR file is a JAR file that has a module descriptor, module-info.class, in the top-level directory (or root) directory.

One Jar could contain only one module.

To fix you problem you have to split your project (create several maven modules)

like image 179
Peter Gyschuk Avatar answered Sep 29 '22 02:09

Peter Gyschuk