Java怎样更改未命名的按钮名,Java 9中创建了多少个未命名的模块?

I am trying to understand how JPMS works.

From here

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.

Please, note ...on the classpath will be contained in the Unnamed Module. Module is singular.

From here

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.

Again unnamed module. Module is singular.

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?

解决方案

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

In short

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.

In more detail

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.

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.

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

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.

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.

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).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值