是否可以禁用 Java 9 中的模块?

Is it possible to disable modules in Java 9?

我使用 OSGI,这是我想禁用模块的主要原因,因为我真的不需要另一个模块框架。是否可以这样做,例如使用命令行选项?如果是,那又如何?

是的,你当然可以,正如受访者在这里所说的那样

Trisha Gee: Many people don’t realize you can use Java 9 and all its shiny new features WITHOUT using Jigsaw, i.e. you can use Java 9 very happily without migrating any of your code. There are some things which have changed in Java 9 (e.g. hiding away internal APIs) but theoretically, if your application was doing all the right things to begin with, there should be no problem compiling and running with Java 9.

看看 entire interview but As you saw we will have two types for Java Applications one for modular world and another for non-module system that's why Red Hat and IBM voted no for JSR 376 as mentioned here 但他们在那之后投了赞成票!

有关 Java 9 模块系统OSGI 的更多信息,请查看 here

希望有用

没有关闭模块系统的选项 - 它始终处于活动状态。这会影响 access to JDK-internal APIs, dependencies on Java EE modules, Split packages, and a lot of other small details。如果您希望您的应用程序在 Java 9.

上 运行,您的代码和依赖项必须应对这些迁移挑战

不过,您绝不会被迫创建模块。您可以完全忽略 module-info.java 并继续将所有 JAR 放到 class 路径上。模块系统会默默地将它们全部捆绑到 unnamed module 中,这是为最大兼容性而创建的。您甚至不会注意到模块系统就在那里(假设您已经克服了我之前描述的挑战)。