The baby and the bathwater
Peter Levart
peter.levart at gmail.com
Wed Mar 28 07:28:23 UTC 2018
On 03/26/18 20:08, mark.reinhold at 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
More information about the jigsaw-dev
mailing list