yes, !Whatever.class.getModule().isNamed() Rémi
----- Mail original ----- > De: "Peter Levart" <peter.lev...@gmail.com> > À: "mark reinhold" <mark.reinh...@oracle.com>, "jigsaw-dev" > <jigsaw-dev@openjdk.java.net> > Envoyé: Mercredi 28 Mars 2018 09:28:23 > Objet: Re: The baby and the bathwater > On 03/26/18 20:08, mark.reinh...@oracle.com 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