1

I am doing a Javafx application in Apache Felix along with some experiments using iPOJO.

First is I called the Application.launch() method in a different class and then start an another class containing the iPOJO @Requires like this:

public class JavafxApp extends Application {
    @Override
    public void start(Stage primaryStage){
        /* Do nothing here because I thought I can initialize JavaFX in a different class */
    }

    public static void start(){
        Platform.runLater(() -> {
            launch(JavafxApplication.class);
        });
    }
}


@Component
@Instantiate
public class MyApplication {
    @Requires
    LibraryClass class;

    @Validate
    public void start(){
        JavafxApp.start();
        class.someMethod();
    }

}

This implementation throws this exception, java.lang.IllegalStateException: Toolkit not initialized but the iPOJO located the implementation class of the LibraryClass interface.

After some research I found out that the application should be inside the class that extends the javafx.application.Application so I did some restructuring.

@Component
@Instantiate
public class JavafxApp extends Application {

    @Requires
    LibraryClass class;

    @Override
    public void start(Stage primaryStage){
        class.someMethod();
    }

    @Validate
    public void start(){
        launch(JavafxApp.class);
    }

}

Edit

The LibraryClass interface and implementation:

@Component
@Provides
@Instantiate
public class LibraryClassImplementation implements LibraryClass {

    public void someMethod(){
        system.out.println("Hello Javafx using iPOJO");
    }

}

public interface LibraryClass {
    public void someMethod();
}

Now the iPOJO throws a RuntimeException and the LibraryClass becomes null and the application throws a NullPointerException.

My questions are:

  • Is it possible to use iPOJO in this situation?
  • If it is what is the right way to use iPOJO in a JavaFX application?

Thanks in advance! :D

megamoth
  • 695
  • 2
  • 12
  • 27
  • you should include a lot more info. what does LibraryClass look like? is it correctly ipojo-ized?? how does JavafxApp relate to MyApplication or LibraryClass?? – Hilikus Feb 04 '15 at 15:14
  • Yes the interface is correctly ipojo-ized, and I am using the `maven-ipojo-plugin:1.12.1` with `ipojo-bundle` goal – megamoth Feb 04 '15 at 15:18

1 Answers1

0

A JavaFX application instance has to be created by the JavaFX Platform using one of the static launch methods of the Application class. AFAIK it's not possible that some other framework such as iPOJO instantiates the class. In the second implementation however you've annotated the Application with some iPOJO (?) annotations, which will create an instance of the class, I guess. But it's the launch method, which should create the application instance, not a framework.

In the first implementation you're trying to call the launch method in the JavaFX Application Thread. But it's the launch method which starts the JavaFX Platform and the JavaFX Application Thread. Also note that the launch methods does not return until the application exits.

That said, note that I've released some Early Access versions of Drombler FX, a new Rich Client Platform for JavaFX based on OSGi (Apache Felix) and Maven.

As an application framework it makes sure JavaFX and OSGi will get started properly and it provides the main window.

You can read more about Drombler FX here: http://puces-blog.blogspot.ch/search/label/Drombler

So far I'm using Declarative Services (generated from the Apache Felix SCR Annotations), but I guess it should also be possible to use iPOJO for new services.

There's a Getting Started page which explains how to create, build and run a Drombler FX sample application with a few simple steps.

Puce
  • 37,247
  • 13
  • 80
  • 152
  • @Pruce can you give me some insights on why it didn't work since you are an expert in this area? Thanks by the way :D – megamoth Feb 16 '15 at 18:04
  • @Arjay A JavaFX application instance has to be created by the JavaFX platform using one of the static launch methods of the Application class. AFAIK it's not possible that some other framework such as iPOJO instantiates the class. The launch methods do not return until the application exits. The launch method will call the start method, you shouldn't call it explicitly. – Puce Feb 16 '15 at 18:46
  • Yes that was the first implementation, in the second part where I call `launch(JavafxApp.class);` instead of `JavafxApp.start();`, the `iPOJO` is still not working. Is it that `iPOJO` is not compatible with the `Javafx` thread? – megamoth Feb 16 '15 at 19:14
  • @Arjay My comment applies to both implementations (various aspects). E.g. in the second implementation you've annotated the Application with some iPOJO (?) annotations, which will create an instance of the class, I guess. But it's the launch method, which should create the application instance, not a framework. Then you're calling launch from the start method? That won't work. The launch method will call the start method not the other way around. The method also has an annotation, which is probably not supported like this (@Validate). – Puce Feb 17 '15 at 12:03
  • @Arjay The launch method will start the JavaFX platform and the JavaFX Application Thread. So, yes, this is another thread than the thread used by iPOJO. – Puce Feb 17 '15 at 12:04
  • Why don't you edit the answer which contains some explanation on why it didn't work and then add your suggestions for `Drombler FX` so I can accept the answer. I found the github repository and its empty so I have some personal question for you, Why do you find `sourceforge.net` as the better hosting site for your project? :D – megamoth Feb 17 '15 at 12:49
  • @Arjay Please see my updated answer. Regarding GitHub: I suggest to discuss this here: http://issues.drombler.org/69 – Puce Feb 18 '15 at 22:34