-5

I creating an application which involves login of two types of users. Upon login the application should load the respective UI. I searched on the Internet for a solution , which involves using reflection package. But that is either loading a main class and then invoking a method , else load all classes. I have the code for those two types of users in two different packages and currently i run the app with those packages in already in the working directory(i.e under one project name)

The final logic is that: i have three jars.

  1. main.jar
  2. admin.jar
  3. tchr.jar

main.jar consists of login ui. after verifying the passwords the app should load either admin.jar or tchr.jar

Im using javafx, and i want to use the same "Scene" object for modification. I used a BorderPane with top as Menubar and center as login. Both admin.jar and tchr.jar use a GridPane Upon login i intend that (suppose user is admin) the BorderPane sets its center the GridPane from admin.jar

Its much like how IDE uses its plugins, In Eclipse after downloading a particular plugin the ide automatically recognizes the available plugins and modifies the ui accordingly

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
pebble
  • 331
  • 2
  • 13

1 Answers1

-1

IF it is a commertial and industrial project I recommend you to use OSGI as a dynamic modules solution. Otherwise you should take a closer look at Reflection&Java class loading to build your own lite solution.

To load UI dynamicly you should use FXMLLoader. Store your GridPanes as a fxmls in your dynamic jar and then use similar code below to load them at runtime:

    public static Node loadResource(URL resource, Object controller){
    final FXMLLoader loader = new FXMLLoader(resource);
    if (controller!=null) loader.setController(controller);  
    try {
        Node node = loader.load();
        log.debug("resource {} loaded", resource);
        return node;
    } catch (IOException e) {
        log.error("could not load resource {}",resource, ExUtils.getRootCause(e));
        return null;
    }
}
rvit34
  • 1,967
  • 3
  • 17
  • 33
  • thanks, its a personal project,I don't want to use FXML, and can u plz give some good links for java reflection tutorial – pebble Feb 07 '17 at 19:14
  • @NumaNuma See [How should I load jars dynamically at runtime](http://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime) – rvit34 Feb 07 '17 at 21:03