Can classes of same package spread across multiple Jar files?

后端 未结 5 847
北荒
北荒 2021-01-04 01:43

I am using some classes from a JAR file and they belong to a package (com.abc.xyz).

The class am writing also belongs to that package but I won\'t be able to bundle

5条回答
  •  执笔经年
    2021-01-04 01:59

    It's probably not something that you should want to do. If it's in the same package, should it not be packaged together (I believe Jigsaw intends to allow splitting packages between modules, but that's a different kettle of fish).

    It can be blocked if either package is marked sealed in the manifest. I would recommend marking whole jars as sealed as a matter of course.

    It can also be blocked if there are different signers on the classes and the classes are loaded by the same class loader.

    If you load classes using a different class loader, although the "namespace" will be the same, you won't actually get package (and relevant part of protected) access.

提交回复
热议问题