2

How to use JavaFX classes inside Eclipse Plugin?

Apparently I am unable to add jfxrt.jar somehow, because it depends on java version and I don't know under which java my plugin will run.

UPDATE

In the "duplicate" question How to use JavaFX 2 SDK in Eclipse? it is answered either to set classpath to jafrt.jar or to use e(fx)clipse

First option looks not portable, because path to java may vary.

And I had failed with second. I have installed e(fx)eclipse into my application but can't figure which plug-ins to include into runtime config.

Community
  • 1
  • 1
Dims
  • 47,675
  • 117
  • 331
  • 600
  • 1
    I don't think it is a dup because how i understand it he wants to develop an eclipse plugin which makes use of JavaFX – tomsontom Feb 25 '14 at 22:57
  • For Java11: a) I got all the openjfx (https://mvnrepository.com/artifact/org.openjfx) jar files b)Put them in the lib folder of my eclipse plugin c) Include them in the runtime classpath of my manifest file d) Included the corresponding packages in the exported runtime packages in the manifest file... to also provide the OpenJfx classes for dependent Eclipse plugins – Stefan Oct 31 '18 at 11:37
  • OpenJfx might requre some code changes, e.g. FXCanvas =>JFXPanel – Stefan Oct 31 '18 at 11:44

2 Answers2

1

The only option you have today with Java7 or Java8 is to make use of Equinox Adapter Hooks. e(fx)clipse provides those for free and they are already used by other Eclipse tools like the Spring IDE.

You can find a tutorial on how to integrate JavaFX into your Eclipse Plugins at https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial2

Please note that the tutorial is pointing to the nightly builds who only work with Luna & Java8 if you want to target Kepler / Java7 you need to use the released version of e(fx)clipse which is at http://download.eclipse.org/efxclipse/runtime-released/0.9.0/site

tomsontom
  • 5,856
  • 2
  • 23
  • 21
-1

The easiest way would be to download the latest version of Java7 and use that to start eclipse (Java7 now has JavaFX packaged with it).

Otherwise I believe you would need to specify it either in your shortcut to eclipse (I'm assuming a Windows OS):

"C:\Program Files\...\eclipse.exe" -vm "C:\Program Files\...\javaw" -Xbootclasspath "C:\Program Files\...\jre\lib\jfxrt.jar"

Or you could create a _JAVA_OPTIONS environment variable containing the same information about the classpath:

-Xbootclasspath "C:\Program Files\...\jre\lib\jfxrt.jar"

The JVM should pick that up.

Please note, this is highly OS specific and the file paths need to be adjusted for your system.

edit

The JVM argument has been updated per the suggestion by @tomsontom

Nick Rippe
  • 6,465
  • 14
  • 30
  • Your answer does not make any sense in an env like OSGi – tomsontom Feb 25 '14 at 22:56
  • an Eclipse Plugin is per definition an OSGi-Bundle - he wants to develop an Eclipse Plugin which makes use of JavaFX - Eclipse will not care about your launch argument of the classpath because OSGi has its own Classloader System – tomsontom Feb 25 '14 at 23:06
  • @tomsontom My interpertation of the question is that he has a Plugin that's not OSGi which he needs to get working. If he's developing a plugin, that wasn't clear in the question. – Nick Rippe Feb 25 '14 at 23:07
  • even then your answer would not help - once more Eclipse does not care what you pass as the classpath - the only possibility would be to modify the bootclasspath because Equinox by default is falling back to it. – tomsontom Feb 25 '14 at 23:10
  • @tomsontom You seem to know more about Eclipse than I do. I believe my first section (Using the latest version of Java7) will still help. I'll edit my answer to change the JVM argument. – Nick Rippe Feb 25 '14 at 23:16