Протестируйте Apache Felix с Java 8 и JavaFX

Я работаю над примером с JavaFX 2.2 и Java 8. Я создал этот простой активатор Apache Felix:

Активатор:

import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator
{

    Stage stage;

    @Override
    public void start(BundleContext context) throws Exception
    {

        Platform.runLater(new Runnable()
        {
            @Override
            public void run()
            {
                stage = new Stage();
                BorderPane pane = new BorderPane();
                Scene scene = new Scene(pane, 400, 200);
                pane.setCenter(new Label("This is a JavaFX Scene in a Stage"));
                stage.setScene(scene);
                stage.show();
            }
        });
        System.out.println("Main Module is loaded!");

    }

    @Override
    public void stop(BundleContext context) throws Exception
    {
        Platform.runLater(new Runnable()
        {
            @Override
            public void run()
            {
                stage.close();
            }
        });
        System.out.println("Main Module is unloaded!");
    }
}

POM

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>DX-57</groupId>
    <artifactId>DX-57_Main</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>bundle</packaging>

    <name>DX-57_Main OSGi Bundle</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>5.0.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instr,uctions>
                        <Import-Package>*</Import-Package>
                        <Bundle-Activator>dx57.dx._main.Activator</Bundle-Activator>
                        <Export-Package>*</Export-Package>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>build-for-felix</id>
            <dependencies>
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.main</artifactId>
                    <version>4.2.1</version>
                    <scope>provided</scope>
                </dependency>
                <!-- To include a shell:
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.gogo.shell</artifactId>
                    <version>0.10.0</version>
                </dependency>
                -->
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <id>compile</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <pathconvert property="plugins.jars" pathsep="${path.separator}">
                                            <path refid="maven.runtime.classpath"/>
                                            <map from="${project.build.directory}${file.separator}classes" to=""/>
                                        </pathconvert>
                                        <pathconvert pathsep=" " property="bundles">
                                            <path path="${plugins.jars}"/>
                                            <mapper>
                                                <chainedmapper>
                                                    <flattenmapper/>
                                                    <globmapper from="*" to="file:modules/*" casesensitive="no"/>
                                                </chainedmapper>
                                            </mapper>
                                        </pathconvert>
                                        <propertyfile file="${project.build.directory}/config.properties">
                                            <entry key="felix.auto.start" value="${bundles} file:modules/${project.build.finalName}.jar"/>
                                            <entry key="org.osgi.framework.bootdelegation" value="*"/>
                                        </propertyfile>
                                        <copy file="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}" tofile="${project.build.directory}/felix.jar"/>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.4</version>
                        <executions>
                            <execution>
                                <id>create-executable-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>${basedir}/src/main/assembly/felix.xml</descriptor>
                                    </descriptors>
                                    <finalName>${project.build.finalName}</finalName>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>run-on-felix</id>
            <dependencies>
                <dependency>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>org.apache.felix.main</artifactId>
                    <version>4.2.1</version>
                    <scope>provided</scope>
                </dependency>
                <!-- org.apache.felix:org.apache.felix.gogo.shell:0.6.1 useless from Maven since stdin is swallowed -->
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <configuration>
                            <target>
                                <property name="vm.args" value=""/>
                                <pathconvert property="plugins.jars" pathsep="${path.separator}">
                                    <path refid="maven.runtime.classpath"/>
                                    <map from="${project.build.directory}${file.separator}classes" to=""/>
                                </pathconvert>
                                <makeurl property="urls" separator=" ">
                                    <path path="${plugins.jars}"/>
                                    <path location="${project.build.directory}/${project.build.finalName}.jar"/>
                                </makeurl>
                                <propertyfile file="${project.build.directory}/run.properties">
                                    <entry key="felix.auto.start" value="${urls}"/>
                                    <entry key="felix.auto.deploy.action" value="uninstall,install,update,start"/>
                                    <entry key="org.osgi.framework.storage" value="${project.build.directory}${file.separator}felix-cache"/>
                                    <entry key="org.osgi.framework.bootdelegation" value="*"/>
                                </propertyfile>
                                <makeurl property="run.properties.url" file="${project.build.directory}/run.properties"/>
                                <java fork="true" jar="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}">
                                    <sysproperty key="felix.config.properties" value="${run.properties.url}"/>
                                    <jvmarg line="${vm.args}"/>
                                </java>
                            </target>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Ошибка:

[rcbandit@Laptop felix-framework_JavaFX]$ /opt/jdk1.8.0/bin/java -jar bin/felix.jar
ERROR: Bundle DX-57.Main [1] Error starting file:/home/rcbandit/Desktop/test/felix-framework_JavaFX/bundle/DX-57_Main-1.0-SNAPSHOT.jar (org.osgi.framework.BundleException: Activator start error in bundle DX-57.Main [1].)
java.lang.ClassCastException: dx57.dx._main.Activator cannot be cast to org.osgi.framework.BundleActivator
    at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4336)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2141)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1291)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)
    at java.lang.Thread.run(Thread.java:724)
____________________________
Welcome to Apache Felix Gogo

g! 

Я добавил внешние пакеты в файл config.properties:

org.osgi.framework.system.packages.extra=javafx.application, \
com.sun.browser.plugin, \
com.sun.deploy.uitoolkit.impl.fx, \
com.sun.deploy.uitoolkit.impl.fx.ui, \
com.sun.deploy.uitoolkit.impl.fx.ui.resources, \
com.sun.deploy.uitoolkit.impl.fx.ui.resources.image, \
com.sun.glass.events, \
com.sun.glass.ui, \
com.sun.glass.ui.delegate, \
com.sun.glass.ui.gtk, \
com.sun.glass.ui.mac, \
com.sun.glass.ui.win, \
com.sun.glass.ui.x11, \
com.sun.glass.utils, \
com.sun.javafx, \
com.sun.javafx.animation, \
com.sun.javafx.animation.transition, \
com.sun.javafx.applet, \
com.sun.javafx.application, \
com.sun.javafx.beans, \
com.sun.javafx.beans.annotations, \
com.sun.javafx.beans.event, \
com.sun.javafx.binding, \
com.sun.javafx.charts, \
com.sun.javafx.collections, \
com.sun.javafx.collections.annotations, \
com.sun.javafx.collections.transformation, \
com.sun.javafx.css, \
com.sun.javafx.css.converters, \
com.sun.javafx.css.parser, \
com.sun.javafx.cursor, \
com.sun.javafx.effect, \
com.sun.javafx.embed, \
com.sun.javafx.event, \
com.sun.javafx.font, \
com.sun.javafx.fxml, \
com.sun.javafx.fxml.builder, \
com.sun.javafx.fxml.expression, \
com.sun.javafx.geom, \
com.sun.javafx.geom.transform, \
com.sun.javafx.iio, \
com.sun.javafx.iio.bmp, \
com.sun.javafx.iio.common, \
com.sun.javafx.iio.gif, \
com.sun.javafx.iio.jpeg, \
com.sun.javafx.iio.png, \
com.sun.javafx.image, \
com.sun.javafx.image.impl, \
com.sun.javafx.jmx, \
com.sun.javafx.logging, \
com.sun.javafx.menu, \
com.sun.javafx.perf, \
com.sun.javafx.property, \
com.sun.javafx.property.adapter, \
com.sun.javafx.robot, \
com.sun.javafx.robot.impl, \
com.sun.javafx.runtime, \
com.sun.javafx.runtime.async, \
com.sun.javafx.runtime.eula, \
com.sun.javafx.scene, \
com.sun.javafx.scene.control, \
com.sun.javafx.scene.control.behavior, \
com.sun.javafx.scene.control.skin, \
com.sun.javafx.scene.control.skin.caspian, \
com.sun.javafx.scene.control.skin.resources, \
com.sun.javafx.scene.input, \
com.sun.javafx.scene.layout.region, \
com.sun.javafx.scene.paint, \
com.sun.javafx.scene.shape, \
com.sun.javafx.scene.text, \
com.sun.javafx.scene.transform, \
com.sun.javafx.scene.traversal, \
com.sun.javafx.scene.web, \
com.sun.javafx.scene.web.behavior, \
com.sun.javafx.scene.web.skin, \
com.sun.javafx.sg, \
com.sun.javafx.sg.prism, \
com.sun.javafx.stage, \
com.sun.javafx.tk, \
com.sun.javafx.tk.desktop, \
com.sun.javafx.tk.quantum, \
com.sun.javafx.util, \
com.sun.media.jfxmedia, \
com.sun.media.jfxmedia.control, \
com.sun.media.jfxmedia.effects, \
com.sun.media.jfxmedia.events, \
com.sun.media.jfxmedia.locator, \
com.sun.media.jfxmedia.logging, \
com.sun.media.jfxmedia.track, \
com.sun.media.jfxmediaimpl, \
com.sun.media.jfxmediaimpl.platform, \
com.sun.media.jfxmediaimpl.platform.gstreamer, \
com.sun.media.jfxmediaimpl.platform.java, \
com.sun.media.jfxmediaimpl.platform.osx, \
com.sun.openpisces, \
com.sun.prism, \
com.sun.prism.camera, \
com.sun.prism.d3d, \
com.sun.prism.d3d.hlsl, \
com.sun.prism.image, \
com.sun.prism.impl, \
com.sun.prism.impl.packrect, \
com.sun.prism.impl.paint, \
com.sun.prism.impl.ps, \
com.sun.prism.impl.shape, \
com.sun.prism.j2d, \
com.sun.prism.j2d.paint, \
com.sun.prism.paint, \
com.sun.prism.ps, \
com.sun.prism.render, \
com.sun.prism.shader, \
com.sun.prism.shape, \
com.sun.prism.tkal, \
com.sun.prism.util.tess, \
com.sun.prism.util.tess.impl.tess, \
com.sun.scenario, \
com.sun.scenario.animation, \
com.sun.scenario.animation.shared, \
com.sun.scenario.effect, \
com.sun.scenario.effect.impl, \
com.sun.scenario.effect.impl.hw, \
com.sun.scenario.effect.impl.hw.d3d, \
com.sun.scenario.effect.impl.hw.d3d.hlsl, \
com.sun.scenario.effect.impl.prism, \
com.sun.scenario.effect.impl.prism.ps, \
com.sun.scenario.effect.impl.prism.sw, \
com.sun.scenario.effect.impl.state, \
com.sun.scenario.effect.impl.sw, \
com.sun.scenario.effect.impl.sw.java, \
com.sun.scenario.effect.impl.sw.sse, \
com.sun.scenario.effect.light, \
com.sun.t2k, \
com.sun.webpane.perf, \
com.sun.webpane.platform, \
com.sun.webpane.platform.event, \
com.sun.webpane.platform.graphics, \
com.sun.webpane.sg, \
com.sun.webpane.sg.prism, \
com.sun.webpane.sg.prism.resources, \
com.sun.webpane.sg.prism.theme, \
com.sun.webpane.sg.theme, \
com.sun.webpane.webkit, \
com.sun.webpane.webkit.dom, \
com.sun.webpane.webkit.network, \
com.sun.webpane.webkit.network.about, \
com.sun.webpane.webkit.network.data, \
com.sun.webpane.webkit.unicode, \
javafx.animation, \
javafx.beans, \
javafx.beans.binding, \
javafx.beans.property, \
javafx.beans.property.adapter, \
javafx.beans.value, \
javafx.collections, \
javafx.concurrent, \
javafx.embed.swing, \
javafx.embed.swt, \
javafx.event, \
javafx.fxml, \
javafx.geometry, \
javafx.scene, \
javafx.scene.canvas, \
javafx.scene.chart, \
javafx.scene.control, \
javafx.scene.control.cell, \
javafx.scene.effect, \
javafx.scene.image, \
javafx.scene.input, \
javafx.scene.layout, \
javafx.scene.media, \
javafx.scene.paint, \
javafx.scene.shape, \
javafx.scene.text, \
javafx.scene.transform, \
javafx.scene.web, \
javafx.stage, \
javafx.util, \
javafx.util.converter, \
org.osgi.framework.wiring, \
netscape.javascript

Есть идеи, как решить проблему?

ОБНОВИТЬ

После удаления<Export-Package>*</Export-Package> Я получаю эту ошибку:

[rcbandit@Laptop felix-framework_JavaFX]$ /opt/jdk1.8.0/bin/java -jar bin/felix.jar
ERROR: Bundle DX-57.Main [1] Error starting file:/home/rcbandit/Desktop/test/felix-framework_JavaFX/bundle/DX-57_Main-1.0-SNAPSHOT.jar (org.osgi.framework.BundleException: Activator start error in bundle DX-57.Main [1].)
java.lang.IllegalStateException: Toolkit not initialized
    at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:201)
    at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:196)
    at javafx.application.Platform.runLater(Platform.java:52)
    at dx57.dx._main.Activator.start(Activator.java:20)
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1291)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)
    at java.lang.Thread.run(Thread.java:724)
____________________________
Welcome to Apache Felix Gogo

g! 

Ответы на вопрос(2)

Ваш ответ на вопрос