12

Everytime I try to create a new java project Eclipse keeps asking if I want to add a module-info java file to the source folder. It's getting pretty annoying as there's no immediately obvious option to opt out of this check.

IDE for Java Developers, Photon release 4.8.0

Raedwald
  • 46,613
  • 43
  • 151
  • 237
AUzun
  • 151
  • 1
  • 2
  • 9
  • 4
    On the second _New Java Project_ dialog page there is a checkbox to create the `module-info.java` file. Unfortunately, this checkbox is enabled by default and its status is not remembered. You can report this feature request to Eclipse. – howlger Sep 04 '18 at 05:08
  • Confusingly, this was only an issue on my fresh Mac install. Using the latest Windows version I did not need to uncheck the checkbox. Not sure which is a better approach, but consistency across platforms would be nice. – Eric H. Dec 31 '19 at 21:46

2 Answers2

6

See while creating a new project, after you click>> next on the very first dialog "new java project." There is one another dialog box pops up when you click >> finish. It will lead you to the 3rd dialog box which asks for the creation of module-info java file?? & gives you two option create & don't create. You should select "don't create."

Here are some advantages of the file module-info.java contents: To declare a jar file as a named module, one needs to provide a module-info.class file, which is, naturally, compiled from a 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. Let’s look at the file syntax and the keywords you can use.

  • Module module.name – declares a module called module.name.
  • Requires module.name – specifies that our module depends on the module module.name, allows this module to access public types exported in the target module.
  • Requires transitive module.name – any modules that depend on this module automatically depend on module.name.
  • Exports pkg.name says that our module exports public members in package pkg.name for every module requiring this one.
  • Exports pkg.name to module.name the same as above, but limits which modules can use the public members from the package pkg.name.
  • Uses class.name makes the current module a consumer for service class.name.
  • Provides class.name with class.name.impl registers class.name.impl class a service that provides an implementation of the class.name service. opens pkg.name allows other modules to use reflection to access the private members of package pkg.name.
  • Opens pkg.name to module.name does the same, but limits which modules can have reflection access to the private members in the pkg.name.

One great thing about the module-info.java syntax is that the modern IDEs would fully support your efforts of writing them. Perhaps all of them would work beautifully. I know that IntelliJ IDEA does content assist, quick fixes of the module files when you import classes from the module you haven’t required yet, and so on. I don’t doubt Eclipse IDE and NetBeans IDE offer the same.

Lance Kind
  • 949
  • 12
  • 32
tushar_lokare
  • 461
  • 1
  • 8
  • 22
  • What do you say to those who say that defining dependencies without semantic versioning makes no sense? And to be exact, there are no keywords you can use in `module-info.java` (`module`, `requires`, etc. are not keywords, otherwise it would not be possible to use them as module or package names). – howlger Sep 04 '18 at 21:14
  • 1
    Your answer would be a lot easier to read if it was laid out better, e.g. by splitting into paragraphs https://meta.stackexchange.com/questions/18614/style-guide-for-questions-and-answers – pateksan Nov 15 '19 at 22:58
  • 1
    What's the big picture on the value of modules? The following doesn't matter to me because I'm not clear why I need dependencies within modules or anything policed: "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" – Lance Kind Dec 13 '19 at 18:29
  • 2
    This doesn't really solve the problem. I don't want to go through several steps just to have the popup not appear, for this requires even larger number of clicks. I just want to type the name of the project, hit Enter and have the Eclipse create the project like before (not have an intermediate module-info interfere and need to hit Esc). It's just annoying. The advantages of the module-info, although useful to know, are not the question here, the question is how to permanently disable the popup (it's a settings question). So far, no way, as far as I can tell... it keeps annoying every day... – Martin Apr 27 '20 at 13:07
2

Perhaps this is not a perfect solution, but it will stop asking if you choose to use Java version 8 compiler (JavaSE-1.8). If you need any newer Java version, I'm affraid don't have an answer.

enter image description here

Martin
  • 1,276
  • 1
  • 10
  • 13