4

So, for every freaking time I want to use JavaFX 8 component, I have to google the exact name of the package, and manually type

 import packageName;

I'll put in more detail.

Let's say I want to create a StackPane

 StackPane stackPane = new StackPane(new ImageView(this.getClass().getResource("/images/about_icon.png").toString()));
 stackPane.setAlignment(Pos.CENTER);

Several classes there. When I use ctrl + o (cmd + o in Mac), then it should import the required package.

But it doesn't.

In fact, I have to google the exact name of StackPane. So, I googled it, I found it that it's under javafx.scene.layout.StackPane

So, I do import javafx.scene.layout.StackPane;

StackPane is fixed.

Now Eclipse is complaining about ImageView and I'm repeating the above same steps for ImageView.

And so on.

How can this be improved?

I'm using Eclipse Mars. Jdk 8. Mac OS X El-Capitan.

Fadils
  • 1,508
  • 16
  • 21
  • I don't use Eclipse, instead writing it out by hand in Notepad++. I like finding the classes by myself. It's not that hard! – Jonathan Lam Oct 28 '15 at 05:05
  • Possible duplicate of http://stackoverflow.com/questions/15592775/javafx-is-not-recognized-in-eclipse? – Jonathan Lam Oct 28 '15 at 05:06
  • The question has very little information for us to help. Please add more information to your question, for e.g. the environment you are using, jdk version etc. These information make it easier for people to offer a solution to your question. – ItachiUchiha Oct 28 '15 at 05:21
  • curious: did it work as expected with an earlier version of eclipse? – kleopatra Oct 28 '15 at 08:53
  • At least one should have gotten restricted access warnings and maybe this bug has been fixed by not allow auto-import! At Eclipse is perfectly right it eg also auto-suggests com.sun.* APIs because from a JSR point of view they are NONE public APIs hence found on the ext-classpath – tomsontom Oct 28 '15 at 16:13
  • @tomsontom as I understand the question, it's about **public** api in the javafx scope. So I think eclipse is not at all _perfectly right_ in not auto-importing. And before jdk9 I wouldn't even see its rightness in not auto-importing com.sun.** classes. Maybe I misunderstand your comment (and your tweeds), though. – kleopatra Oct 28 '15 at 23:46
  • 1
    So take the following - I'm developing a Swing application which should deployed to linux-desktop but on my workstation I only have oracle-jdk. I start typing and get a proposal for ObservableList and find it useable - this application will break miserably when deployed to a linux client who has a standardized JDK but not Oracle JDK! – tomsontom Oct 28 '15 at 23:51
  • @tomsontom Swing and ObservableList - you must be dreaming ;-) On a more serious note: I honestly wasn't aware of fx not being standard - as much as I dislike fx, that's ridiculous in the light of not having anything else as UI. – kleopatra Oct 29 '15 at 00:01

3 Answers3

10

You need to install e(fx)clipse in order to have JavaFX development tooling support.

For this

  1. Open Help -> Install New Software
  2. Select the Software Site for Mars http://download.eclipse.org/releases/mars
  3. Disable Group items by category (unfortunately the e(fx)clipse team forgot to add a category)
  4. Filter for e(fx)
  5. Select e(fx)clipse - IDE
  6. Next
  7. Next
  8. Accept the license
  9. Finish

enter image description here After that you need to restart Eclipse and should have proper JavaFX support.

Dirk Fauth
  • 4,128
  • 2
  • 13
  • 23
  • hmm... nothing like that was necessary before mars (didn't upgrade my eclipse yet, so can't say if/what anything changed), it simply worked. Just noticed that the OP is on Mac, I'm on Win - might that make a difference? – kleopatra Oct 28 '15 at 08:48
  • To verify your statement I just downloaded Luna SR2 and there it also doesn't work without e(fx)clipse tooling. Are you sure that you really don't have such tooling installed? Or did you modify the build path yourself somehow? I'm just asking because JavaFX is on the extended classpath and therefore it shouldn't work without some modifications out of the box. – Dirk Fauth Oct 28 '15 at 09:30
  • interesting - yeah, it's a very bare-bones Kepler-SR2 plus jdk8 patch installation (build eclipse.buildId=4.3.2.M20140221-1700) It's rather old, but then, it's working :), no additional tooling. Win vs. Mac? – kleopatra Oct 28 '15 at 09:45
  • Works fine on my Eclipse installations on Mac (I have Luna with e(fx)clipse, Mars JEE without). – James_D Oct 28 '15 at 12:18
  • Ah, OK: I downloaded the latest version and did recreate something similar. – James_D Oct 28 '15 at 13:57
  • tracked the working in my win contexts to using the jdk (vs. the public jre) as system library – kleopatra Oct 29 '15 at 12:50
10

On a clean installation of the latest version of Eclipse for Java Developers (Mars.1 release 4.5.1), I was able to reproduce this (more or less).

I fixed it by setting the access restrictions on the JRE system library.

From your Project properties, choose "Java Build Path", select the "Libraries" tab, and expand the JRE System Library:

enter image description here

The first entry in that list is "Access Rules". Select that and press "Edit", then press "Add":

For "Resolution", choose "Accessible", and for "Rule Pattern", enter "javafx/**".

enter image description here

Hit "OK" until all the dialogs are gone. Your CMD-SHIFT-O options should now be able to find javafx packages.

James_D
  • 201,275
  • 16
  • 291
  • 322
  • 1
    Note that if you install e(fx)clipse, these steps should be unnecessary. – James_D Oct 28 '15 at 14:51
  • good dig! But whatever the technical subtilities (as hinted at in a comment to http://stackoverflow.com/a/33385361/203657 and elsewhere) might be: I do expect an IDE to support **everything** that's in a standard Java SE release **without** me doing acrobatics (or installing additions) – kleopatra Oct 28 '15 at 23:41
1

After having learnt my lesson of the day - javafx is not standard java! - I was still curious why I didn't experience any problems with the imports of javafx.*

Actually, I can reproduce the issue in Mars on Win7: all I had to do was to use the public jre as system library of the project. In my environment, I normally use the jdk as system library which doesn't seem to have the problem.

So for Windows, a simple solution (aka: not requiring the installation of additional tooling nor tweaking access permissions on the project level) is to use a java system library backed by a jdk.

Community
  • 1
  • 1
kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • That is interesting. I always work against an Execution Environment that is mapped to a JDK. In such a case it doesn't work. But if I switch to the Workspace default JRE that is mapped to the same JDK, javafx imports can be resolved. I think this should be filed as a ticket. – Dirk Fauth Oct 29 '15 at 13:44
  • I created a ticket for this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=480997 ... looks like the usage of an Execution Environment is causing this. – Dirk Fauth Oct 29 '15 at 13:55