mardi 21 décembre 2021

Java Modules: access to public member failed

I am trying to get 2 Java 9+ modules to play nice with each other while using reflection, and while only using the module-path, but for the life of me can't get it to work. (Putting them on the classpath poses of course no problem.)

  1. One module contains a BeanReader class that uses reflection to collect a JavaBean's properties and then MethodHandles to read them
  2. The other module contains a simple JavaBean (Person) and a Main class. The Main class instantiates a Person and passes it to the BeanReader. The BeanReader reads one of its properties. In module-info.java I've defined it as an open module.

The command line invocation of the main class looks like this:

java --module-path naturalis-common.jar:test.jar -m test/Main

Yet I keep getting an IllegalAccessException. What am I missing? It all seems pretty bare-bones vanilla.

This is the 2nd module's module-info.java:

open module test {
  requires nl.naturalis.common;
  exports test;
}

And this is the 2nd module's Main class:

package test;
import nl.naturalis.common.invoke.BeanReader;

public class Main {
  public static void main(String[] args) {
    Person p = new Person(2, "Jan");
    BeanReader<Person> br = new BeanReader<>(Person.class);
    br.read(p, "id");
  }
}




Aucun commentaire:

Enregistrer un commentaire