JavaFX on mac install not found - javafx

So I am trying to run a simple helloworld app for the javafx but its packages cannot be found. Ok so must be some kind of path issue right?
I have downloaded the co-bundled version from here:
http://www.oracle.com/technetwork/java/javafx/downloads/index.html
You would expect that a co-bundled would install just as the SE package installed. I have searched the net and people give windows answers with windows path's to a mac problem. Which is really IMO a java problem because either you co-bundle like you said you did and install both or keep them separate!
I have yet to find an appropriate solution to getting javafx to be included in the compile, that does not involve including long paths.
EDIT:
After installing netbeans and creating a javafx project, it had no trouble locating the appropriate packages. I think at this point it should be clear that FX is co-bundled with the SE version however they ( java maintainers ) have decided to make it decidedly uneasy to get FX working from the command line. Any insight into this otherwise dumb decision?

Some choices:
Use JavaFX 8 which places JavaFX is on the default runtime classpath.
Package your application with the Oracle JavaFX deployment tools that will insert code in your app to find JavaFX.
Manually add the path to jfxrt.jar to your your compile and runtime classpath if you cannot do either of the above.
For 3 you can find jfxrt.jar for the jre under:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
If you have jdk7 installed, you can run a JavaFX app (packaged using the JavaFX deployment tools) from the command line using something like the following:
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
java -version
java -jar application.jar
If it is just the JRE7 installed and no JDK, then you can use:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -jar application.jar

Per option #3 in Jewelsea's answer, here's how it looked in my ant build file:
<property name="jfx.dir" value="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib"/>
<path id="project.class.path">
<pathelement path="${classpath}"/>
<pathelement location="${jfx.dir}/jfxrt.jar"/>
</path>
<target name="compile"
description="Compiles the source code.">
<mkdir dir="${classes.dir}"/>
<javac includeantruntime="false"
srcdir="${src.dir}"
destdir="${classes.dir}">
<classpath refid="project.class.path"/>
<exclude name="**/package-info.java"/>
</javac>
</target>

I am using JavaFX in class work right now in University. I just found that no JDK version would run JavaFX EXCEPT 10.0.2. Uninstall all other versions and run 10.0.2 and JavaFX should work.

Related

JavaFX Application does not start when JAVA_HOME is set

I package my JavaFX Application with java 1.8u45 and Inno5 as an .exe file with the ant. And the executable works when installing it on a computer, where either Java 8 is installed and set as JAVA_HOME environment variable or when no java is installed at all. But if e.g. java 1.6 or less is installed and the JAVA_HOME variable is set to java 1.6 the application will not start with the very generic error Failed to start jvm. Starting the bundled .jar file via java -jar foobar.jar either causes a failure and stops jvm entirely or prints unsupported major.minor version 52.0.
How can I tell JavaFX to never use JAVA_HOME?
The application is packaged as an exe with the fxbuilder, using:
<fx:deploy verbose="true" embedJNLP="false" extension="false" includeDT="false" offlineAllowed="true" outdir="${basedir}/target/deploy" outfile="application" nativeBundles="exe" updatemode="background">
<!-- To list all classes loaded -->
<!--<fx:jvmarg value="-verbose:class"/>
<fx:platform basedir="${java.home}" />-->
<fx:info title="App" vendor="Me" />
<fx:application refId="fxApplication" />
<fx:resources refid="appRes" />
</fx:deploy>
When having bundled with the JRE, the native launcher looks up for the filename corresponding .cfg-file, which contains the information about the JRE-location (there should be some line like this: app.runtime=$APPDIR\runtime)
If that .cfg-file only contains app.runtime=(without the value), the native launcher does search for local installed JREs:
https://github.com/teamfx/openjfx-8u-dev-rt/blob/master/modules/fxpackager/src/main/native/library/common/Package.cpp#L120
On windows, the native launcher checks inside the system-registry and does NOT check for JAVA_HOME-property!
https://github.com/teamfx/openjfx-8u-dev-rt/blob/master/modules/fxpackager/src/main/native/library/common/WindowsPlatform.cpp#L188
The same goes for other platforms, but they are checking for JRE_HOME, but never JAVA_HOME.
I would suggest you to check the windows-registry (was JDK 6 installed AFTER a JDK 8 which replaced the higher-version?)!
Disclaimer: I'm the maintainer of the javafx-maven-plugin and creator of the javafx-gradle-plugin.

e(fx)clipse JavaFX still missing

I am running XUbuntu x64 14.04.4 LTS on my PC, with eclipse Mars.2 Release (4.5.2) and JDK 8 properly linked up to my eclipse (via ini file).
So basically, I "upgradet" to e(fx)clipse. Then I crated a new "JavaFX project". When I tried to run it, I got the error The import javafx.application cannot be resolved.
A quick google search brought up, that I need to add the jfxwt.jar from my java 1.8 directory (in my case /opt/Oracle_Java/jdk1.8.0_91/jre/lib/).
But the error didn't went away. I also tried the build options but nothing seemed to change anything.
First of all, I included the wrong jar. whoops. thanks to #DVarga for the tip.
But that wasn't the problem. So here are all the steps I took, to create a working e(fx)clipse environment:
Download the latest eclipse version and add the e(fx)clipse package.
Update to the latest JDK and reference that in the eclipse.ini file (1)
Tell ecplipse the path for the latest JDK. Although this tutorial is for MACs, it works pretty much the same in linux. There are a few differences tho:
The preferences menu is in window > preferences
The JRE type is not MacOS X VM but rather Standard VM
The JRE home path is the jdk1.8.0_VERSION folder (in my case /opt/Oracle_Java/jdk1.8.0_91)
I didn't need to add any other jar for javaFX to work properly.
(1) How to add the Java 1.8 path to eclipse
if you get the error "JavaFX was disabled because your java version is to old" (or something like this) you need to update to at least Java 1.8 and edit the eclipse.ini file in the eclipse folder.
There you have to look for the line -vm. In the next line is a path to an old Java version. Change that to the new path. It should look like this: /path/to/jdk1.8.0_VERSION/jre/bin/ in my case it is /opt/Oracle_Java/jdk1.8.0_91/jre/bin/

Cant find JavaFX in JDK8 for Arm

I downloaded and installed JDK8u33 for ARM on my beaglebone black, and according to this documentation (http://docs.oracle.com/javase/8/embedded/jdk-arm-8u6/index.html) javafx is included and supported.
However, I can not find jfxrt.jar anywhere in the JRE or JDK, and using javac on a simple javafx program yields "javafx.application" is not a package.
What gives?
As #eckig says, since the 8u33 for ARM version, Oracle has removed JavaFX from the ARM distribution.
To run any JavaFX application you can downgrade your version to the last JDK8u6 that supported JavaFX, or you can provide a valid jfxrt.jar.
And you can do it following this tutorial, cross building OpenJFX for ARM, or just using some already built distribution like this one hosted on the JavaFXPorts project.
Once you have downloaded armv6hf-sdk.zip, unzip it and you need to add this command line option to attach this external source to the classpath, with the extension mechanism:
-Djava.ext.dirs=<path to armv6hf-sdk>/rt/lib/ext
For instance, you need this to run one of the JavaFX old samples from its actual path:
sudo /opt/jdk1.8.0_33/bin/java -Djava.ext.dirs=<path to armv6hf-sdk>/rt/lib/ext -jar BrickBreaker.jar
The latest version of the Java Development Kit for ARM processors (JDK 8u33 for ARM) no longer supports JavaFX Embedded, it has been all of the tech news, for example here: http://jaxenter.com/jdk-arm-without-javafx-end-javafx-embedded-114212.html

How to find out JavaFX version

This should be easy, but I can't figure out how.
Is there any way to find out which JavaFX version is installed. And I DON'T mean programmatically via System.getProperty("javafx.runtime.version") , which returns an empty string on my computer, although JavaFX is installed.
I would rather like to have something like java -version on console, but in order to get the JavaFX version.
Alternatively it would be sufficient to know if JavaFX is installed at all. I just have some customers who can't run my swing/javaFX app and would like to tell them to check whether JavaFX is installed.
You can't really do this the same way you do with the Java runtime. The difference is that java is a machine executable that launches the JVM. JavaFX is just a set of library classes; it's not really an executable in the same sense.
It looks like the System property that you can read at runtime is kept in jre/lib/javafx.properties, so you can do something like
cat $JAVA_HOME/jre/lib/javafx.properties
or whatever the Windows equivalent is, if you're running on Windows. However, if the System property you get at runtime is blank, then I suspect this file doesn't exist. As dfeuer commented, it would help to know your JRE version.
Update:
The relationship between JDK/JRE version and JavaFX version is as follows.
Beginning with JRE 1.7.0 update 6, JavaFX was included with the JRE, but was not on the classpath. So for JRE 1.7.0, update 6 and later, the jfxrt.jar file is included in JAVA_HOME/jre/lib. The javafx.properties file which contains the JavaFX version information is in the same directory, though in theory at least the JRE version will determine the JavaFX version (since they were shipped together).
Just inspecting the JDK 1.7.0 versions I have installed on my machine, the mapping from JDK version to JavaFX version is:
/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk javafx.runtime.version=2.2.0
/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk javafx.runtime.version=2.2.4
/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk javafx.runtime.version=2.2.4
/Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk javafx.runtime.version=2.2.5
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk javafx.runtime.version=2.2.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk javafx.runtime.version=2.2.21
/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk javafx.runtime.version=2.2.25
/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk javafx.runtime.version=2.2.40
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk javafx.runtime.version=2.2.45
Beginning with JRE 1.8.0, JavaFX was included with the JRE and was placed on the classpath; so it's effectively a full part of the core libraries. In version 1.8.0, the jfxrt.jar file is in JAVA_HOME/jre/lib/ext (which automatically makes it part of the classpath). The javafx.properties file which contains the JavaFX version information is still in JAVA_HOME/jre/lib. The version numbering for JavaFX in version 1.8.0 (appears to) simply mimic the JRE version:
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk javafx.runtime.version=8.0.0
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk javafx.runtime.version=8.0.5
/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk javafx.runtime.version=8.0.20
So with your customers, you can simply ask them to do java -version and for the most part, you'll be able to deduce the JavaFX version. On some rare occasions you may need to dig a little deeper.
A sort-of-related note: if you are shipping an application to customers and you need to determine a specific version, consider using a self contained application, in which you include a JRE (and JavaFX runtime) with the application.
For Ubuntu 18.04 the JavaFX version can be found in /usr/share/openjfx/lib/javafx.properties. A simple command should show you the version you have.
$ cat /usr/share/openjfx/lib/javafx.properties
javafx.version=11.0.2-internal
javafx.runtime.version=11.0.2-internal+0-2019-02-19-093139
javafx.runtime.build=0
Perhaps your installation has something similar?
If you are using Netbeans 15 on Windows 10, look in the file:
C:\Program Files\NetBeans-15\netbeans\javafx\VERSION.txt
On my machine, it contains 11

How to build into Desktop Java?

So I know you can use ant and mvn to test the project, but I was wondering if there was a way to deploy the project directly as a executable jar or otherwise compile it into a format that can be directly ran? Thanks!
if you are serious about making a launchable desktop program (and especially if its going to be a game), you should use launch4j to make an exe file that launches the jar. It isn't hard to use, and it makes the program much more end user friendly
If your project was generated from the 1.7.2 PlayN archetype or newer, that functionality is already built in. Simply invoke:
mvn package
and a dependencies-included jar file will be generated in:
yourgame/java/target/yourgame-java-1.0-SNAPSHOT-jar-with-dependencies.jar
you can test it by running it standalone like so:
java -jar yourgame/java/target/yourgame-java-1.0-SNAPSHOT-jar-with-dependencies.jar
If your game was generated via an older PlayN archetype, the you can add the necessary bits to your java/pom.xml file by pasting in this in (merging with any existing <build> <plugins> blob):
maven-assembly-plugin
2.4
jar-with-dependencies
${mainClass}
make-assembly
package
single
Then just run mvn package as above to generate the file. Note that you will need to be building against PlayN 1.7.2 or newer as that version is the first one that supported automatic unpacking of the LWJGL native libraries needed to run on the desktop.

Resources