Although I doubt that making sure a library _only_ works on the module path is a good idea, would it make sense to introduce a helper method for this check? Something like:
Module.assertOnModulePath() ? 2018-03-28 9:41 GMT+02:00 Remi Forax <[email protected]>: > yes, > !Whatever.class.getModule().isNamed() > > Rémi > > ----- Mail original ----- > > De: "Peter Levart" <[email protected]> > > À: "mark reinhold" <[email protected]>, "jigsaw-dev" < > [email protected]> > > Envoyé: Mercredi 28 Mars 2018 09:28:23 > > Objet: Re: The baby and the bathwater > > > On 03/26/18 20:08, [email protected] wrote: > >> Stephen closes with a specific suggestion: > >> > >> "There needs to be a way for a library author to insist that the > >> modular jar file they are producing can only be run on the > module-path > >> (with any attempt to use it on the class-path preventing application > >> startup). This would eliminate the need for testing both class-path > >> and module-path." > > > > 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"); > > } > > } > > > > > > Regards, Peter >
