如何让 Eclipse 停止要求在创建新 Java 项目时创建模块信息 java 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52158125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get Eclipse to stop asking to create a module-info java file on new Java project creation?
提问by AUzun
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.
每次我尝试创建一个新的 Java 项目时,Eclipse 都会不断询问是否要向源文件夹添加一个模块信息 Java 文件。这变得非常烦人,因为没有立即明显的选项可以选择退出此检查。
IDE for Java Developers, Photon release 4.8.0
面向 Java 开发人员的 IDE,Photon 版本 4.8.0
回答by tushar_lokare
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."
在创建新项目时,在第一个对话框“新建 Java 项目”上单击 >> 下一步后查看。单击>>完成后,会弹出另一个对话框。它会引导您进入第三个对话框,要求创建 module-info java 文件??& 为您提供了创建和不创建两个选项。您应该选择“不创建”。
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-info.java 内容的一些优点: 要将 jar 文件声明为命名模块,需要提供一个 module-info.class 文件,该文件自然是从 module-info.java 文件编译而来. 它声明了模块系统内的依赖关系,并允许编译器和运行时监管应用程序中模块之间的边界/访问冲突。让我们看一下您可以使用的文件语法和关键字。
- 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.
- Module module.name – 声明一个名为 module.name 的模块。
- Requires module.name – 指定我们的模块依赖于模块module.name,允许该模块访问目标模块中导出的公共类型。
- 需要可传递的 module.name - 任何依赖于此模块的模块都会自动依赖于 module.name。
- Exports pkg.name 表示我们的模块为每个需要这个模块的模块导出包 pkg.name 中的公共成员。
- 将 pkg.name 导出到 module.name 与上述相同,但限制了哪些模块可以使用包 pkg.name 中的公共成员。
- 使用 class.name 使当前模块成为服务 class.name 的使用者。
- 使用 class.name.impl 提供 class.name 注册 class.name.impl 类的服务,该服务提供 class.name 服务的实现。opens pkg.name 允许其他模块使用反射来访问包 pkg.name 的私有成员。
- 打开 pkg.name 到 module.name 的作用相同,但限制了哪些模块可以反射访问 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.
module-info.java 语法的一大优点是现代 IDE 将完全支持您编写它们的工作。也许所有这些都会很好地工作。我知道 IntelliJ IDEA 会提供内容帮助,当您从不需要的模块导入类时,模块文件的快速修复,等等。我不怀疑 Eclipse IDE 和 NetBeans IDE 提供相同的功能。