14 Replies Latest reply: Apr 20, 2012 12:05 PM by 932148 RSS

    JavaFX in an Eclipse view

    912421
      Hello,

      I'm trying to create an Eclipse plugin; a regular view that would show some graphical elements using JavaFX. I am using JavaFX 2, Eclipse 3.6 and Java 1.6.
      1. All I did is that I created the most simple view from the Eclipse example projects.
      2. Then I created a new plugin JavaFX.lib using the "Plug-in from Existing JAR Archives". It contains the deploy.jar, javaws.jar, jfxrt.jar, plugin.jar JAR files.
      3. I modified the SampleViev.createPartControl(Composite parent) method to look like this:
           public void createPartControl(Composite parent) {
                    Composite composite = new Composite(parent, SWT.EMBEDDED);
                    FXCanvas fxPanel = new FXCanvas(composite.getShell(), SWT.NONE);  //<====== EXCEPTION
                    Group group = new Group();
                    Scene scene = new Scene(group);
                    Button button = new Button("JFX Button");
                    group.getChildren().add(button);
                    fxPanel.setScene(scene);
              }
      But now I'm getting an exception
      java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Canvas
           at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
           at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
           at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
           at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
           at java.lang.ClassLoader.defineClass1(Native Method)
           at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
           at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
           at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
           at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:601)
           at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:567)
           at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:490)
           at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:478)
           at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:458)
           at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
           at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:400)
           at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
           at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:473)
           at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
           at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
           at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
           at graphicalview2.views.SampleView.createPartControl(SampleView.java:101)
      Could you please advise how to solve this problem?
      Also am I going the right way? Is this the proper way to have JavaFX in eclipse views and editors?

      BTW I also tried to add the four JAR files mentioned above to the Classpath on the Runtime tab of the
      plugin.xml, but then I got the following exception. Could you please explain what is the reason for getting this exception?
      java.lang.UnsatisfiedLinkError: Invalid URL for class: bundleresource://497.fwk6586390:2/com/sun/glass/utils/NativeLibLoader.class
           at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(Unknown Source)
           at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(Unknown Source)
           at com.sun.glass.utils.NativeLibLoader.loadLibrary(Unknown Source)
           at com.sun.glass.ui.Application$1.run(Unknown Source)
           at java.security.AccessController.doPrivileged(Native Method)
           at com.sun.glass.ui.Application.loadNativeLibrary(Unknown Source)
           at com.sun.glass.ui.win.WinApplication.<clinit>(Unknown Source)
           at com.sun.glass.ui.win.WinPlatformFactory.createApplication(Unknown Source)
           at com.sun.glass.ui.win.WinPlatformFactory.createApplication(Unknown Source)
           at com.sun.glass.ui.Application.Run(Unknown Source)
           at com.sun.javafx.tk.quantum.QuantumToolkit.startup(Unknown Source)
           at com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
           at javafx.embed.swt.FXCanvas.initFx(Unknown Source)
           at javafx.embed.swt.FXCanvas.<init>(Unknown Source)
           at graphicalview2.views.SampleView.createPartControl(SampleView.java:101)
      Thanks,
      Attila
        • 1. Re: JavaFX in an Eclipse view
          jsmith
          Also am I going the right way? Is this the proper way to have JavaFX in eclipse views and editors?
          I don't know as I don't use SWT, but you could try looking at the http://fxexperience.com/2011/12/swt-interop/ post which might give you some pointers.
          • 2. Re: JavaFX in an Eclipse view
            918430
            The FXCanvas has multiple dependencies on the org.eclipse.swt plugin so list this bundle in the dependency tab of your manifest.mf. Right now I'm writing a little tutorial how to bundle FX in an Eclipse RCP application without extra JavaFX installation on the target machine. I post the link here later.

            Edited by: 915427 on 18.02.2012 06:31
            • 3. Re: JavaFX in an Eclipse view
              867289
              Wolfgang Geck wrote:
              The FXCanvas has multiple dependencies on the org.eclipse.swt plugin so list this bundle in the dependency tab of your manifest.mf. Right now I'm writing a little tutorial how to bundle FX in an Eclipse RCP application without extra JavaFX installation on the target machine. I post the link here later.
              And have you managed to launch javafx from eclipse RCP? Because I didn't. But after some investigation I have found that there is a check in com.sun.glass.utils.NativeLibLoader that doesn't allow to load native libraries from OSGi bundle:
              if(!classUrlString.startsWith("jar:file:") || classUrlString.indexOf("!") == -1)
              throw new UnsatisfiedLinkError((new StringBuilder()).append("Invalid URL for class: ").append(classUrlString).toString());
              • 4. Re: JavaFX in an Eclipse view
                jsmith
                You can search the JavaFX Jira and it will provide further information on OSGI native library loading issues for JavaFX.
                To do this create an account on http://javafx-jira.kenai.com and type OSGI in the search box.
                You will find issues like "NativeLibLoader fails to load libWebPaneJava.dylib when loading jfxrt.jar via OSGi" http://javafx-jira.kenai.com/browse/RT-17919.
                • 5. Re: JavaFX in an Eclipse view
                  918430
                  In my opinion JavaFX is an interesting technology and thanks to FXCanvas easy to integrate in Eclipse/SWT based applications. The biggest problem I see is that estimated 95% of the users can't run your application because they have no FX installed and normally won't risk this additional step just for running your single application. On the other hand if more and more applications run on JavaFX more and more people are willing to install it. So to break this chicken and egg dilemma maybe it's a good start to bundle JavaFX in your applications if required. One possible approach is the use of OSGI fragments for different operating systems (the same mechanism that is used to deliver SWT on multiple platforms).

                  You find a sample application (for windows 32 bit) that shows the use of OSGI fragments here http://download.glue-box.de/fx_demo.zip . All necessary JavaFX libraries are packed in the host plugin javafx.osgi_2.1.0.jar and the win32 fragment javafx.osgi.native.win32_x86_2.1.0.jar. The source code is also available in the plugin de.gluebox.fxsample.

                  To be honest right now I only tested win32/win64 machines and I really have no idea what the oracle guys say to this solution especially when it comes to licensing issues? However right now this solution works fine on windows machines and an additional disk space of less than 10 MB is acceptable in many situations.

                  Edited by: Wolfgang Geck on Feb 21, 2012 11:40 PM
                  • 6. Re: JavaFX in an Eclipse view
                    918979
                    Hi all,
                    I'm currently encountering the same problem...

                    I've copied javafx.osgi & javafx.osgi.native.win32_x86 in my target platform. I also added the de.gluebox.fxsample project in my target platform just to test.
                    But the sample plugin can't find javafx objects :( Even if I use the "Open Type" dialog in eclipse (CTRL+T) I can't FXCanvas and other javafx classes ... Although I'm sure the plugins have been correctly added in the target platform.
                    If I import the 2 javafx.osgi plugins then I can found javafx classes :|

                    I'm a little disappointed, I was pretty excited to integrate JavaFX in my RCP.

                    Hope you could help me ^^

                    Thanks before,
                    Jonathan
                    • 7. Re: JavaFX in an Eclipse view
                      918430
                      Hi Jonathan,

                      please download the package http://download.glue-box.de/fx_target.zip and attach all containing plugins and fragments to your target platform. Afterwards the build failures should disappear. Remember that this package is just a demonstration of the fragments concept i described in the post above and should NOT be seen as production stable solution. See how the fragment structure is organized, check the manifest and if necessary build your own JavaFX bundles for more recent versions or other operating systems.

                      All the best
                      Wolfgang
                      • 8. Re: JavaFX in an Eclipse view
                        jsmith
                        Hi Wolfgang, thanks for your well though-out post.
                        The biggest problem I see is that estimated 95% of the users can't run your application because they have no FX installed and normally won't risk this additional step just for running your single application.
                        You may be interested in this Jira issue "Add ability to co-bundle Java + JavaFX + App into a single native executable" (http://javafx-jira.kenai.com/browse/RT-19446). This feature is currently scheduled for a future update release. It seems like a slightly different approach to solving a similar problem to what you are are trying to solve with the OSGI bundling. My guess is that a combination of Jigsaw and native packaging would be used to implement this feature, but perhaps OSGI or OSGI compatibility may have part to play.
                        I really have no idea what the oracle guys say to this solution especially when it comes to licensing issues?
                        With regards to licensing, the relevant licensing clause to review is Clause C "LICENSE TO DISTRIBUTE SOFTWARE." from here:
                        http://www.oracle.com/technetwork/java/javase/terms/license/index.html
                        Also review Clause D "LICENSE TO DISTRIBUTE REDISTRIBUTABLES", as that is somewhat more restrictive.
                        As I would read it, as long as you are bundling JavaFX with an application which adds significant additional functionality and not just acting as a distribution point for JavaFX only, then you are OK to distribute it - but that is just my reading in laymans terms, not as a lawyer (and I am not an oracle guy - contact Oracle directly if you have further questions).
                        • 9. Re: JavaFX in an Eclipse view
                          866711
                          http://www.efxclipse.org/ provides an OSGi integration for equinox which is used by the tooling and runtime platform - you can point it to a custom javafx.jar in the next release or make it fall back to the system one - beside that it e.g. provides a wrapper for the FXMLLoader which works in OSGi
                          • 10. Re: JavaFX in an Eclipse view
                            918979
                            thanks, I know the ef(x) project indeed... seems pretty good and I'm gonna try it very soon. But for now I've found the solution with the 2 bundles mentioned above, I've just slightly modified them ^^

                            Thanks all :)
                            • 11. Re: JavaFX in an Eclipse view
                              918430
                              My intention was not to solve the problem of loading any JavaFX classes from within OSGI bundles (something efxclipse already covers !).
                              I explained a mechanism how to deliver JavaFX ( the full runtime including alls DLLS, Libs etc.) in a set of OSGI bundles so you can give your RCP application using JavaFX also to clients that have no JavaFX installed on their computers. This is some kind of workaround unless JavaFX is integral part of JAVA in the future or I can assume it's installed on almost all computers. If you know any better solution please let me know.
                              • 12. Re: JavaFX in an Eclipse view
                                918979
                                Yes, actually my problem was the same you tried to solve :) So I haven't any better solution... I'm gonna wait for the new Java release and see what happen :D
                                • 13. Re: JavaFX in an Eclipse view
                                  866711
                                  What I wanted to explain: Shiping JavaFX with your application will be possible with the next release (or the one afterwards) there are 2 strategies:
                                  a) Search for a javafx install next to your app.exe (similar to how you can simply put the jre next to it and it will be used instead of the system installed one)
                                  b) Ship it with an OSGi-Plugin so that one can easily update it with p2

                                  I hope this clarifies the situation. Simply subscribe to my blog so that you don't miss the release.
                                  • 14. Re: JavaFX in an Eclipse view
                                    932148
                                    Hi,

                                    I had the same problem and I resolved it by adding a dependency to swt.jar to the JavaFX.lib plugin.

                                    Alexandra.