두 프로젝트 (코어 및)가있는 다중 모듈 프로젝트가 있습니다. 아이디어는 코어가 시작될 때마다 A를 실행/실행하는 것입니다.ServiceLoader가 Plugin Jar를 찾는 위치를 사용자 지정하는 방법
ServiceLoader를 찾아보고 플러그인 모듈 폴더에서 코어를 검색하고 호출하도록 사용자 정의 할 수 있습니까?
plugin-Project
+ Core
+ src\main\java
Core.java
+ A
+ src\main\java
A.java
+ Plugins
코어
public class Core extends Application {
private ServiceLoader<View> views;
private BorderPane mainBorderPane;
@Override
public void init() {
loadViews();
}
private void loadViews() {
views = ServiceLoader.load(View.class);
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Ui Application");
mainBorderPane = new BorderPane();
mainBorderPane.setTop(createMenuBar());
Scene scene = new Scene(new Group(), 800, 605);
scene.setRoot(mainBorderPane);
stage.setScene(scene);
stage.show();
}
private MenuBar createMenuBar() {
MenuBar menuBar = new MenuBar();
Menu viewMenu = new Menu("Views");
menuBar.getMenus().add(viewMenu);
ToggleGroup toggleGroup = new ToggleGroup();
views.forEach(v -> {
RadioMenuItem item = new RadioMenuItem(v.getName());
item.setToggleGroup(toggleGroup);
item.setOnAction(event -> {
Label label = new Label(v.getName());
mainBorderPane.setLeft(label);
mainBorderPane.setCenter(v.getView());
});
viewMenu.getItems().add(item);
});
return menuBar;
}
public static void main(String[] args) {
launch(args);
}
}
View.java
public interface View {
String getName();
Node getView();
}
시나리오
내가 현재 일하고있는 응용 프로그램은 다중 모듈 독립 실행 형 데스크탑 응용 프로그램입니다. 예를 들어, 코어는 왼쪽에 팬이 있습니다 (왼쪽 창). 왼쪽 창은 LeftPane
이라는 인터페이스를 구현하는 모든 모듈의 nodes
을 수락합니다. 은 LeftPane
인터페이스를 구현합니다. 코어가 실행될 때마다 폴더,이 경우 플러그인을 검색하여 A를 포함한 모든 번들을 자동으로 시작해야합니다. 그러면 A가 왼쪽 패널을 채 웁니다.
@ Program-Me-Rev는' ServiceLoader'. – hotzst