I am a relative newbie to programming, I have a bit of experience building Swing apps and I now want to try my hand at learning JavaFX. I am using Eclipse Kepler as my IDE.
I understood from the JavaFX website that JavaFX is included in the JDK7 - Quote: "The first step in getting started with JavaFX is to download and install the Java SE 7 JDK, which includes the JavaFX runtime libraries and utilities. See the JDK 7 and JRE 7 Installation Guide for instructions."
However, when I try to import the Oracle JavaFX HelloWorld example (http://docs.oracle.com/javafx/2/get_started/hello_world.htm) into an Eclipse project I get errors on the JavaFx package imports. The only suggestions I get are to create new classes etc or 'search repositories for javafx.application'
Does this mean that Eclipse does not support JavaFX out of the box?
So my question to the community is two-fold:
1. please explain how to use JavaFX working in Eclipse. I checked out other answers which seem to indicate that I should install f(x)eclipse. But...
before you tell me that this is a duplicate question, my second question is please also help me understand how, when Oracle say that JavaFX is included in JDK7, it is not possible to import those packages regardless of the IDE (just like it is possible with Swing).
Thanks
It is part of the JDK but not on a classpath hence extra work needed with Java7 - on Java8 it is on the ext-classpath - so the correct answer is - something being part of JDK does not mean it is on the classpath by default.
So tools like Eclipse need to take extra care of this.
Since JDK 7 update 51 JavaFX is a part of JDK: release notes
Related
I have been working on some class projects on a work computer with NetBeans 11 and uploading my progress to github. Recently, I came home and pulled my progress down to my laptop which still has netbeans 8. All of a sudden, when I try to run code, I get:
javac: invalid target release: 13
From browsing stackoverflow and other such forums, I gather that 13 refers to the version of the JDK. Apparently, there is some mismatch in my settings (either I am using an old version but NetBeans wants to use something newer, or maybe the other way around).
I went into project > properties > sources and saw a drop down bar titled "Source/Binary Format" with JDK 13 selected. I dropped it down to 9 (a completely random choice) and then tried to run my code again. Voila, it worked.
My questions are simply: What did I just do? Why did it work? Are there any implications for my program to be considered?
If you choose to answer please be aware that I know little about the inner workings of Java, and so a simple explanation is appreciated. I only know how to write the code, not what happens behind the scenes. I'm tempted to blindly plow forward with my coding, but I thought this might be a learning point. Perhaps not.
Basically, your IDE checks your code according to the rules of the language, and those those are different depending on language version because e.g. Java 7 has no lambdas but Java 8 does. Your project was configured to be checked against the rules for Java 13, but the older version of NetBeans wasn't able to do that, so you've asked for it to be checked against the rules for Java 9 instead. This will have no impact on your project unless you want to use features introduced in Java 10 or later.
The other purpose of this drop-down menu is if you want to compile your project so that it can be run using an older version of Java. If you're distributing a piece of software for users who still only have Java 8 installed, then you would want to limit the project to Java 8.
I have installed Apache Netbeans IDE 10.0 on Linux Mint, and followed this recommendation to activate JEE support ( https://superuser.com/questions/1404517/how-to-enable-java-ee-in-apache-netbeans-ide-10 ). I have restarted Netbeans and JEE annotations are marked as errors "Incompatible types : Path cannot be converted to annotation". This happens with all Java EE annotations, and I don't know how to solve this.
I have tried to do clean and build but still the same. Here is a screen shot of some sample errors:
You are having problems because the solution you followed for the accepted answer to the superuser question How to Enable Java EE in Apache Netbeans IDE 10 is wrong.
That answer advises you to use an Update Center to download some plugins used in NetBeans 8.2. That was an appropriate workaround on NetBeans 9, but wrong for NetBeans 10 since the appropriate plugins you need are already available (on the Tools > Plugins > Available Plugins tab), and you just need to install them. You don't need to obtain any plugins from any Update Center for Java EE, and doing so will probably be harmful.
See this SO answer to the SO question How to create Web Application in Apache Netbeans 10? for details on which of the available plugins need to be installed.
Notes:
I think you should first reinstall NetBeans 10 if possible, to start with a clean environment.
If that is not possible you should first uninstall those NetBeans 8.2 plugins you added to NetBeans 10, and then restart NetBeans.
Although the SO answer I linked to is for a slightly different question, the solution applies equally to your problem.
Although not related to your question at all, you might consider also upgrading to Apache NetBeans to version 11.1 if that is possible. If you did that you would still follow exactly the same process detailed in the linked answer for installing the Java EE plugins.
I have just installed the JDK1.8.0 32 bit version on my computer and that all seemed to work nicely. I then followed the instructions on this stackoverflow page to add tools.jar to the Eclipse (although, to be honest, I'm not quite sure what that means?). I'm still getting the error: "Requires JDK 5.0 or later. Please download it from http://java.sun.com/j2se/1.5/".
Could someone please help me understand what the problem is? Also, please let me know if I haven't given enough information, this is my first attempt at using Eclipse and I don't know if you need any other info.
Thanks
Mike
The Oracle JDK installation does not install Java in the location where Eclipse by default looks for it.
I would suggest that you go to http://java.com/en/download/installed.jsp and follow instructions to get a default Java installation on your system.
Eclipse will then use that to run itself. You can then tell Eclipse about your Java 8 JDK in Preferences -> Java -> Installed JRE's and that it is to be used by default by the projects you write.
Note that there is not full support for the new Java 8 facilities in Eclipse yet. That will most likely come in Eclipse 4.4 scheduled for June (http://wiki.eclipse.org/Simultaneous_Release)
When you make a new project, make sure it's using the JRE you want. You may have to change it from default to "use project specific JRE", and then select the 1.8.
I have installed jdk1.7.0_15.
JavaFX's download page says the following:
JavaFX 2.2.7 contains the latest security fixes and is co-bundled with
the latest JDK 7 for Windows, Mac and Linux.
Download Java SE 7 with JavaFX 2.2.7
Like a good noob, I followed the instructions and installed the JDK. Now when I look for jfxrt.jar file that I can import to Eclipse as a user library, I can not find it. There are a few other JavaFX related libraries in JDK's lib folder but I do not understand what to import next.
Most of the tutorials on Google, including the one by Java, are very old.
Please help me get started with JavaFX
I recommend using e(fx)clipse.
e(fx)clipse is a plugin to assist JavaFX development in Eclipse which will fix your classpath issue and provide you with many other useful features as well as step by step documentation and code completion assistance.
Great question. I remember having the same problem when I started. Here is a little step by step guide.
1) Make a new JavaFx project (This is actually the same as a Java project, it just comes with a more suitable skeleton)
2) If you're getting errors like 'Can't find javafx.application' add the jfxrt.jar by right clicking on the libraries and select 'Add folder/Jar' You will have to browse to your jdk folder and find jfxrt.jar. Here is where it is located in my jdk:
/jdk1.7.0_15/jre/lib/jfxrt.jar
3) For the third step I suggest checking out this example. This example comes with sample code and I used it to copy and paste till I got a little more comfortable in javafx.
I'm using Mac OS X, Netbeans 7.3 Beta 2 and JDK 7 u12.
Netbeans cannot see the JavaFX library. I thought that the JavaFX library comes with JDK 7?
Netbeans see's and uses JDK 7 (coming from JDK 6 I have now lost my retina icons and text!), but when I try and add a library there is no JavaFX library available.
I've gone through the steps shown on Netbeans website to configure and create a JavaFX application, which is where I found that for OS X I need JDK 7, but I have had no luck.
What am I missing?
jdk7u12 is still pre-release software and may be incompatible with NetBeans.
Specifically, a recent change in the JavaFX structure is HEADS-UP: jfxrt.jar moving to jre/lib/ext. If you try using jdk7u12 with a version of NetBeans coded before the JavaFX structure change (such as NetBeans 7.3 beta 2), it may not work out of the box. In the meantime, I suggest using a production version of the jdk (such as jdk7u11) until NetBeans update their software to work correctly with the relocated jfxrt.jar library.
I know you note that you have followed steps on the NetBeans website, but you don't link to them. Ensure that you have correctly configured a NetBeans JavaFX Platform as detailed in the NetBeans JavaFX setup tutorial (Although that tutorial is currently for NetBeans 7.1 and 7.2, hopefully it will also work for your 7.3 beta). Also, make sure that when you create your project, you create a "JavaFX Application" in NetBeans - as opposed to a regular "Java Application".
If you are still having issues, list your compile errors in your question.
when I try and add a library there is no JavaFX library available.
JavaFX is not configured as a library on NetBeans - it is part of a "JavaFX Platform" as detailed in the setup link in this answer.
coming from JDK 6 I have now lost my retina icons and text!.
Kind of unrelated, but JavaFX in JDK8 will support retina displays (scheduled release data Sept, 2013).
John,
You might try posting your question on the Oracle JavaFX 2.0 and Later Forum:
https://forums.oracle.com/forums/forum.jspa?forumID=1385
Please feel free to tweet the URL of your question to me #JavaFXpert and I'll follow up to make sure it gets answered.
Thanks,
Jim Weaver