Java 9中创建了多少个未命名的模块? [英] How many unnamed modules are created in Java 9?

查看:216
本文介绍了Java 9中创建了多少个未命名的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解JPMS的工作原理.

I am trying to understand how JPMS works.

此处

类路径还没有完全消失.所有JAR(是否为模块化) 并且类路径上的类将包含在未命名模块"中. 类似于自动模块,它导出所有包并读取所有 其他模块.但是,它显然没有名字.为了那个原因 因此,命名应用程序模块无法要求和读取它. 未命名的模块又可以访问所有其他模块.

The classpath is not completely gone yet. All JARs (modular or not) and classes on the classpath will be contained in the Unnamed Module. Similar to automatic modules, it exports all packages and reads all other modules. But it does not have a name, obviously. For that reason, it cannot be required and read by named application modules. The unnamed module in turn can access all other modules.

请注意...on the classpath will be contained in the Unnamed Module.模块是单数.

此处

出于兼容性考虑,类路径上的所有代码都打包为一个 特殊的未命名模块,没有隐藏的程序包,可以完全访问 整个JDK.

For compatibility, all code on the classpath is packaged up as a special unnamed module, with no hidden packages and full access to the whole JDK.

再次unnamed module.模块是单数.

我是否正确理解,JPMS中始终只有一个未命名的模块?这是否意味着将在Java9之前开发且未针对Java9更新的应用程序将作为一个未命名的模块加载?

Do I understand right that there is always only one unnamed module in JPMS? Does it mean that applications that were developed before Java9 and not updated for Java9 will be loaded as one unnamed module?

推荐答案

我是否正确理解,JPMS中始终只有一个未命名的模块?

Do I understand right that there is always only one unnamed module in JPMS?

简而言之

通常来说,不会.但是,让我们这样说:如果您将一些甚至所有JAR放在类路径上,而您的应用程序没有创建类加载器来加载任何其他内容,那么您只需要关心一个未命名的模块即可.

Generally speaking, no. But let's put it this way: If you place some or even all JARs on the class path and your application does not create class loaders to load any additional content, then there is only one unnamed module you need to care about.

详细信息

每个ClassLoader都有

Every ClassLoader has its own unnamed module that it uses to represent classes that it loaded from the class path. This is necessary because the module system requires everything to be in a module.

nullpointer的答案详细说明的那样,默认情况下,应用程序将使用三个单独的类加载器.它可能会启动自己的类加载器,例如加载插件.但是,如果不这样做,所有应用程序代码将最终存储在系统/应用程序类加载器中,因此将存储在相同的未命名模块中.这就是为什么通常只需要关心一个的原因.

As nullpointer's answer explains in detail, an application will by default use three separate class loaders. It is possible that it might spin up its own class loaders, for example to load plugins. If it doesn't do that, though, all application code will end up in the system/application class loader and hence in the same unnamed module. That's why there is typically only one you need to care about.

这是否意味着将在Java9之前开发且未针对Java9更新的应用程序作为一个未命名的模块加载?

Does it mean that applications that were developed before Java9 and not updated for Java9 will be loaded as one unnamed module?

这与代码(应用程序,框架,库)是否以Java 9为目标无关-它仅取决于放置JAR的路径,类路径还是

This has nothing to do with whether code (application, frameworks, libraries) targets Java 9 - it only depends on which path you place a JAR, on the class path or the module path.

如果它在类路径中,它将与其他类路径内容一起在未命名模块中结束.对于没有模块描述符的普通JAR,但对于包含一个的模块化JAR,都是如此.

If it's on the class path, it ends up in the unnamed module together with other class path content. This is true for plain JARs without module descriptor but also for modular JARs that contain one.

如果它在模块路径上,它将获得自己的模块.如果是模块化JAR,它将获得一个显式模块,如全文中所述模块系统的状态-普通的JAR变成了自动模块(请注意复数:每个JAR一个自动模块).

If it's on the module path, it gets its own module. If it's a modular JAR, it gets an explicit module as those described throughout the State of the Module System - plain JARs get turned into automatic modules (note the plural: one automatic module per JAR).

这篇关于Java 9中创建了多少个未命名的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆