I am trying to use dependency injection within my Java (SE) FX application but I am getting the error java: jakarta.inject.Provider.get() is defined in an inaccessible class or interface
when using the following code.
@Log4j2
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Weld weld = new Weld();
try (WeldContainer container = weld.initialize()) {
container.select(MainWindowLoader.class).get().loadMainWindow(primaryStage);
}
}
}
The MainWindowLoader class looks as follows.
public class MainWindowLoader {
public void loadMainWindow(Stage primaryStage) throws Exception {
Parent parent = FXMLLoader.load(getClass().getResource("/MainWindow.fxml"));
Scene scene = new Scene(parent);
final ObservableList<String> stylesheets = scene.getStylesheets();
stylesheets.addAll(getClass().getResource("/css/style.css").toExternalForm());
primaryStage.setTitle("Avengers Manager");
primaryStage.setScene(scene);
primaryStage.show();
}
}
I am using following dependencies.
<!-- weld for dependency injection -->
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>4.0.1.SP1</version>
</dependency>
My one and only module-info.java
files looks like this.
module avengers-manager {
requires weld.se.core;
requires weld.environment.common;
requires weld.core.impl;
requires jakarta.inject;
opens us.tony.stark.avengers-manager;
}
Any ideas?
The solution to this was to use the shaded dependency.
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-shaded</artifactId>
<version>4.0.1.SP1</version>
</dependency>