The baby and the bathwater
Peter Levart
peter.levart at gmail.com
Wed Mar 28 10:01:09 UTC 2018
On 03/28/2018 11:18 AM, Stephen Colebourne wrote:
> On 28 March 2018 at 08:28, Peter Levart <peter.levart at gmail.com> wrote:
>> That's easy to enforce in runtime. Just take a "victim" class from your
>> library that is most often needed when your library is being used (or take a
>> couple of them) and add a class initialization block like the following to
>> them:
>>
>> public class Whatever {
>>
>> static {
>> if (Whatever.class.getModule().getName() == null) {
>> throw new Error("Can only use this library as a module");
>> }
>> }
> Agreed that this has always been possible, but it is code not
> metadata. Really, it should be a startup JPMS error if the module
> isn't running in the expected mode. That way tools like Maven and
> Gradle can also take decisions based on the metadata.
>
> Stephen
Hm, that would be hard to enforce, since what you're asking is for JPMS
to issue an error when the library in question is not part of its search
scope. Class-Path class loader could do that though (by searching for pa
particular "sign" in the jars on the class path even before the JVM
transfers control to MainClass.main()). But modulepath and classpath are
not the only ways a particular jar can be deployed. It can be part of a
.war or .ear. It can be deployed into a system that manages its own
class loader(s), etc. All those mechanisms would have to agree on a
"standard" way of specifying such metadata.
Regards, Peter
More information about the jigsaw-dev
mailing list