2017-01-30 58 views
0

我试图将javafx加载到一个基于OSGi实现的基于swing的软件中。 事情是,每当我尝试从FX instanciate任何类它给我ClassDefNotFoundException。将javaFx加载到Apache felix中

我已经尝试了其他帖子的一些解决方案,但没有任何变化。

这是我的POM的一部分:

 <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <configuration> 
       <instructions> 
        <Import-Package>!javafx.embed.swing.JFXPanel,*</Import-Package> 
        <Embed-Dependency> 
         *;scope=compile;inline=true, 
         javafx.embed.swing.JFXPanel;scope=compile;inline=true 
        </Embed-Dependency> 
        <Embed-StripVersion>true</Embed-StripVersion> 
       </instructions> 
      </configuration> 
     </plugin> 

这是一个让我异常的命令:

JFXPanel J = new JFXPanel(); 

这是个例外:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javafx/embed/swing/JFXPanel 
at br.com.test.SampleTool.<init>(SampleTool.java:87) 
at br.com.test.SampleToolFactory.createDataExplorerView(SampleToolFactory.java:62) 
at org.weasis.base.ui.internal.Activator.dataExplorerChanged(Activator.java:118) 
at org.weasis.base.ui.internal.Activator.lambda$serviceChanged$2(Activator.java:110) 
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) 
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) 
at java.awt.EventQueue.access$500(EventQueue.java:97) 
at java.awt.EventQueue$3.run(EventQueue.java:709) 
at java.awt.EventQueue$3.run(EventQueue.java:703) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) 
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) Caused by: java.lang.ClassNotFoundException: javafx.embed.swing.JFXPanel 
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
at org.apache.felix.framework.ExtensionManager$ExtensionManagerWiring.getClassByDelegation(ExtensionManager.java:1010) 
at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1595) 
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1525) 
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79) 
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
... 18 more 
+0

你尝试使用命令行Dorg.osgi.framework导出包.system.packages.extra = javafx.embed.swing.JFXPanel,http://felix.apache.org/documentation/subprojects/apache-felix-framework/apache-felix-framework-configuration-properties.html – ravthiru

+0

我做到了在eclipse上的vm参数中,我也尝试将Class包含到配置文件中。也许这可能是IDE的问题? –

回答

0

该指令需要修复:

<Embed-Dependency> 
*;scope=compile;inline=true, 
javafx.embed.swing.JFXPanel;scope=compile;inline=true 
</Embed-Dependency> 

嵌入的依赖性可与文物,但javafx.embed.swing.JFXPanel类。

因此,您需要指定具有您需要的所有JavaFX类的工件。因为你要导入这个类

<Import-Package>!javafx.embed.swing.JFXPanel,*</Import-Package>

那么你应该删除此行。

我相信,你正在寻找的东西是这样的:或者

<build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-bundle-plugin</artifactId> 
       <extensions>true</extensions> 
       <configuration> 
        <instructions> 
         <Embed-Dependency>groupId=javafx;artifactId=jfxrt;version=8.0;inline=true</Embed-Dependency>        
        </instructions> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>javafx</groupId> 
      <artifactId>jfxrt</artifactId> 
      <version>8.0</version> 
      <type>jar</type> 
      <scope>system</scope> 
      <systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath> 
     </dependency> 
    </dependencies> 

,您可以添加的JavaFX作为系统包:like this

+0

谢谢你这个工作,你的答案是非常有帮助的。 –