32

I have installed JavaFX 2.0 SDK and now I would like to do an JavaFX application with Eclipse. But how can I use the javafx.* classes in Eclipse?

The official JavaFX Eclipse plugin seem to be for JavaFx 1.2 and outdated.

When I try to install e(fx)clipse plugin, I get this error:

Cannot complete the install because one or more required items could not be found.
  Software being installed: efxclipse 0.0.8.201111131640 (at.bestsolution.efxclipse.feature.feature.group 0.0.8.201111131640)
  Missing requirement: Eclipse DI integration for JavaFX 0.0.8.201111131640 (at.bestsolution.efxclipse.runtime.di 0.0.8.201111131640) requires 'bundle org.eclipse.e4.core.contexts 0.9.0' but it could not be found
  Cannot satisfy dependency:
    From: efxclipse 0.0.8.201111131640 (at.bestsolution.efxclipse.feature.feature.group 0.0.8.201111131640)
    To: at.bestsolution.efxclipse.runtime.feature.feature.group [0.0.8.201111131640]
  Cannot satisfy dependency:
    From: FX Runtime 0.0.8.201111131640 (at.bestsolution.efxclipse.runtime.feature.feature.group 0.0.8.201111131640)
    To: at.bestsolution.efxclipse.runtime.di [0.0.8.201111131640]
ComFreek
  • 29,044
  • 18
  • 104
  • 156
Jonas
  • 121,568
  • 97
  • 310
  • 388

8 Answers8

40

There are two options:

1) EDIT: Since 7u35 (or smth near it) JavaFX was included into base JDK classpath so you can use JavaFX classes right away.

Just set up your projects to use fx libs:

JavaFX 2.0 API is pure Java. So you can create a new Java project and add sdk-path/rt/lib/jfxrt.jar to libraries to use JavaFX in that project.

For cobundled builds in JDK7 path would be next jdk-path/jre/lib/jfxrt.jar

2) Use e(fx)clipse plugin: http://www.eclipse.org/efxclipse/index.html

Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141
  • 6
    Guys, still note, that mentioned e(fx)clipse plugin is not mandatory but useful and is being actively developed. So if you are Eclipse user you may want to monitor e(fx)clipse author blog: http://tomsondev.bestsolution.at/ – Sergey Grinev Jan 24 '12 at 23:35
  • 2
    It took me a while to find, but after installing Java 7u5, the jfxrt.jar file is in (for Windows) C:\Program Files\Oracle\JavaFX x.x sdk\rt\lib\ – Richard Aug 06 '12 at 21:37
  • thanks Segrey ...and Richard. Couldn't find it anywhere.. thought I was losing it. Oracle! – HellishHeat Aug 16 '12 at 17:16
  • 3
    With Java 7 update 7 / FX 2.2 the path seems to have changed, it's now C:\Program Files (x86)\Java\jdk1.7.0_07\jre\lib\jfxrt.jar – stefan.at.kotlin Sep 04 '12 at 11:41
  • For early Oracle Java 8 builds, the location of jfxrt.jar has changed again and is now `%JDK_HOME%\jre\lib\ext\jfxrt.jar` (for jdk installs). Also, for Oracle Java 8, jfxrt.jar is now on the default runtime path, so you do not need to explicitly add it to your classpath nor as a library to your project. – jewelsea Mar 01 '13 at 18:32
  • 2
    How do you know `jfxrt.jar` is pure java? – Dims Feb 26 '14 at 18:43
  • @Dims I worked at Oracle in JavaFX team at the time I answered that question. Also you can check youself, just `jar tvf jfxrt.jar` – Sergey Grinev Feb 26 '14 at 20:14
  • Then why do you advise to set path to `sdk-path/rt/lib/jfxrt.jar`? It is not portable because path can vary. Why don't you advise to include `jfxrt.jar` and deploy it along with the app? I was said here that there are high chances of incompatibility: http://stackoverflow.com/a/22064535/258483 Is this wrong? Thanks. – Dims Feb 27 '14 at 13:19
  • this question is 2.5 years old, you don't need to do it since ~7u35. And you can't just deploy jfxrt.jar, there are dependent native libs and licensing issues. But good point I'll update an answer. – Sergey Grinev Feb 27 '14 at 16:43
13

You can use e(fx)clipse! You can find it here: http://www.eclipse.org/efxclipse/index.html

After download you must to configure the IDE with your JavaFX SDK(must be installed).

All you need to do is to open Window > Preferences > JavaFX and configure the location of your JavaFX-SDK.

You ussualy have it in Program Files > Oracle.

Hope this will help you!

ComFreek
  • 29,044
  • 18
  • 104
  • 156
Valentin Vrinceanu
  • 679
  • 1
  • 12
  • 24
  • 1
    Although Sergey's answer has many votes, I wish this were the accepted solution as IMHO it is a far better solution than adding `jfxrt.jar` to the classpath. – jewelsea Nov 21 '12 at 19:28
4

Based on Sergey Grinev solution, I noticed that we can define this once for all java projects.

  1. Go to Preferences -> Java build path
  2. Select the jvm which is supposed to support javaFx (but whose feature is not yet recognized in Eclipse) and Edit it
  3. Add the sdk-path/rt/lib/jfxrt.jar to it

This way, all your java projects based on this JVM version can support JavaFx and even your older projects (Select each project build path and eventually replace the old jvm with the jvm that you've just edited)

loloof64
  • 5,252
  • 12
  • 41
  • 78
3

To access JavaFx in Java8 with Eclipse Luna (4.4):

Go to Build Path/ JRE/ Access rules/ Edit/ Add/ Accessible: javafx/**

This seems better than editing the classpath file manually or adding the JAR (again) to the build path.

Georg
  • 271
  • 2
  • 2
2

If you don't mind working with java 8, you won't have to jump through any hoola hoops. Just set that as your default jre and javafx imports work out of the box.

mancini0
  • 4,285
  • 1
  • 29
  • 31
2

As an aside, it says it won't install the FX plugin because you are missing org.eclipse.e4.core.contexts bundle. Were you trying to install it into Eclipse Indigo, or 3.8? Or did you follow the instructions on the website and download eclipse 4.2 before you started?

Paul Webster
  • 10,614
  • 1
  • 25
  • 32
0

To install the e(fx)clipse tooling into your already existing Eclipse you have to add an Update site.

There's no released yet available so you need to add the nightly update-site http://download.eclipse.org/efxclipse/updates-nightly/site

Ishwor
  • 181
  • 2
  • 10
0

I installed Eclipse Neon.1 (4.6.1) Then Help => Eclipse Marketplace On find specify "javaFX" and install "e(fx)clise 2.4.0"

Tiago Freitas Leal
  • 693
  • 1
  • 7
  • 13