e(fx)clipse equinox compilation error

Deadly 提交于 2019-12-11 19:55:18

问题


I'm developing an OSGI (Equinox) Based-System and i came across JavaFX, i was trying the e(fx)clipse {OSGI bundle project} and i wrote a simple test project, but it is giving me some compilation errors. i have a main class :

import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class main extends Application {
    private static main _main ;
    public main () {
        _main = this;
    }
    public static main Get_Main(){
        return _main;
    }
    @Override
    public void start(Stage primaryStage) 
    {
        try 
        {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(main.class.getResource("fxml.fxml"));

            primaryStage.setScene(new Scene(loader.load()));
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

and i have a controller for the FXML

import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;

public class controller {
    @FXML
    private AnchorPane _AnchorPane;
    @FXML
    private Button _Btn;

    @FXML
    private void initialize() {
        _AnchorPane.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                _AnchorPane.setStyle("-fx-background-color:red");
            }
        });
    }

    @FXML
    private void _BtnClick() {
        _AnchorPane.setStyle("-fx-background-color:blue");
    }
}

and an Activator for the bundle

import javafx.stage.Stage;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class aCTIVATOR implements BundleActivator {
    private Stage _stage = new Stage();
    private main _main;
    @Override
    public void start(BundleContext context) throws Exception {
        _main = main.Get_Main();
        _main.start(_stage);
    }

    @Override
    public void stop(BundleContext context) throws Exception {
        _stage.close();
    }
}

and this is my manifest file :

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: 
Bundle-SymbolicName: root
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javafx.animation;version="2.0.0",
 javafx.application;version="2.0.0",
 javafx.beans;version="2.0.0",
 javafx.beans.binding;version="2.0.0",
 javafx.beans.property;version="2.0.0",
 javafx.beans.value;version="2.0.0",
 javafx.collections;version="2.0.0",
 javafx.concurrent;version="2.0.0",
 javafx.event;version="2.0.0",
 javafx.fxml;version="2.0.0",
 javafx.geometry;version="2.0.0",
 javafx.scene;version="2.0.0",
 javafx.scene.chart;version="2.0.0",
 javafx.scene.control;version="2.0.0",
 javafx.scene.control.cell;version="2.0.0",
 javafx.scene.effect;version="2.0.0",
 javafx.scene.image;version="2.0.0",
 javafx.scene.input;version="2.0.0",
 javafx.scene.layout;version="2.0.0",
 javafx.scene.media;version="2.0.0",
 javafx.scene.paint;version="2.0.0",
 javafx.scene.shape;version="2.0.0",
 javafx.scene.text;version="2.0.0",
 javafx.scene.transform;version="2.0.0",
 javafx.scene.web;version="2.0.0",
 javafx.stage;version="2.0.0",
 javafx.util;version="2.0.0"
Bundle-Activator: aCTIVATOR
Require-Bundle: org.eclipse.osgi;bundle-version="3.10.0"

so when i go to the Run-Configuration, i choose OSGI-FrameWork and select the

  1. project
  2. org.eclipse.osgi
  3. org.eclipse.fx.javafx
  4. org.eclipse.fx.osgi

and finally it si giving my this compilation error:

!SESSION 2014-10-21 13:32:14.128 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_20
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments:  -dev file:/home/hany/workspace/JavaFX/.metadata/.plugins/org.eclipse.pde.core/New_configuration/dev.properties -os linux -ws gtk -arch x86_64 -consoleLog -console

!ENTRY root 4 0 2014-10-21 13:32:14.618
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Error starting module.
    at org.eclipse.osgi.container.Module.doStart(Module.java:567)
    at org.eclipse.osgi.container.Module.start(Module.java:429)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1551)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1531)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1502)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1445)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.NoClassDefFoundError: javafx/stage/Stage
    at aCTIVATOR.<init>(aCTIVATOR.java:8)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at java.lang.Class.newInstance(Class.java:433)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.loadBundleActivator(BundleContextImpl.java:755)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:706)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:928)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:317)
    at org.eclipse.osgi.container.Module.doStart(Module.java:558)
    ... 8 more
Caused by: java.lang.ClassNotFoundException: javafx.stage.Stage cannot be found by osgi.identity; osgi.identity="root"; type="osgi.bundle"; version:Version="1.0.0.qualifier"
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:365)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:331)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:323)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more
Root exception:
java.lang.NoClassDefFoundError: javafx/stage/Stage
    at aCTIVATOR.<init>(aCTIVATOR.java:8)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at java.lang.Class.newInstance(Class.java:433)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.loadBundleActivator(BundleContextImpl.java:755)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:706)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:928)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:317)
    at org.eclipse.osgi.container.Module.doStart(Module.java:558)
    at org.eclipse.osgi.container.Module.start(Module.java:429)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1551)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1531)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1502)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1445)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.ClassNotFoundException: javafx.stage.Stage cannot be found by osgi.identity; osgi.identity="root"; type="osgi.bundle"; version:Version="1.0.0.qualifier"
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:365)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:331)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:323)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more

!ENTRY org.eclipse.osgi 4 0 2014-10-21 13:32:14.621
!MESSAGE Bundle root_1.0.0.qualifier [4] is not active.

!ENTRY org.eclipse.osgi 4 0 2014-10-21 13:32:14.622
!MESSAGE Could not find bundle: org.eclipse.equinox.console
!STACK 0
org.osgi.framework.BundleException: Could not find bundle: org.eclipse.equinox.console
    at org.eclipse.core.runtime.internal.adaptor.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:58)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:323)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:222)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1426)

!!!!!!!(this was a long one) So any idea or help about this?


回答1:


The reason you see the "java.lang.NoClassDefFoundError" is that Equinox does not consult the Ext-classpath and most likely you don't tell Equinox to use our adaptor hooks who make equinox consult that path.

What you need to do is to:

  1. Ensure that you have org.eclipse.fx.osgi fragment in your launch
  2. Make sure you pass -Dosgi.framework.extensions=org.eclipse.fx.osgi as VM arguments in your launch config
  3. (Update) Preferred option launch with -Dorg.osgi.framework.bundle.parent=ext

Now that I've answered your real question. I can not end with a final note on your style of asking and replying to people. This is not good and I've thought multiple times about whether I should answer. Stop putting exclamation marks in your questions and reply and before putting someone down think twice if this the correct way to talk to someone who tried to help you!



来源:https://stackoverflow.com/questions/26485270/efxclipse-equinox-compilation-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!