package javafx does not exist for sample "mavenproject" netbeans 7.4 - java

I am trying to run the "mavenproject1" file created by doing a "File::new project" and selecting "maven" then "JavaFX Application".
I am using the latest and greatest. I have Java JDK 1.7.0_45 which I installed separately that is configured to build the project. I have Netbeans 7.4 (Build 201310111528) with MAVEN 3 built in. JavaFX is bundled with the JDK 1.7.0_45.
I can make the project execute, but my source files get an error indicating that the JavaFX package does not exist. I added the following to my pom.xlm file which allows Maven to build and execute the source files even though the NB editor cannot find the JavaFX packages:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}\lib\jfxrt.jar</systemPath>
</dependency>
How can I get the NB editor to recognize the JavaFX packages?

If you can, I advise using Java 8 as:
JavaFX is on the default Java classpath in Java 8 but not in Java 7.
As JavaFX is on the default Java 8 classpath, you don't need a system path dependency on jfxrt.jar in your maven project.
As JavaFX is on the default Java 8 classpath NetBeans 7.4 should recognize JavaFX packages with no extra configuration.
You may also want to consider using the javafx-maven-plugin.

Related

Idea says "The JavaFX runtime is not configured. Either use a JDK that has the JavaFX built in, or add a JavaFX library to the classpath"

I recently installed Java 10. The JavaFX project I opened runs with Java 8, and its "Project SDK" and "Project language level" in Idea are both set to use JDK 8, and Java 8 includes the jfxrt.jar file where it's supposed to be (jre/lib/ext). I can build and run the project on the command line with Gradle without issue.
If I modify how Idea starts up to use Java 8, Idea doesn't complain.
So... is this a bug? I'm not up on the new dependency tree stuff, but shouldn't Idea declare JavaFX as a dependency if it needs it? Clearly the project I'm working on is set up fine.
You can follow the steps on the openjfx website to add JavaFX to IntelliJ (look under the JavaFX and IntelliJ section on the left-hand menu).
Install JavaFX from here
Navigate to File -> Project Settings
Install SDK 19
On the Libraries tab, add the JavaFX 19 SDK as a library to the project

Eclipse RCP product export using a certain JDK

My Eclipse Mars 4.5.1. uses JDK 8 to start-up (specified in the eclipse.ini)
My RCP project uses JDK 7. The entire workspace uses 7. I've also included the JavaFX JAR until I migrate the whole project to JDK 8, where I won't need it.
When I try to export the RCP project using the .product file, the exported version has some logs saying that certain classes using JavaFX have compile errors. Even though the exported version is started with JDK 7 (specified in the .ini file), and the JavaFX JAR surely was exported too, these UI components crash.
This whole process works with Eclipse starting with JDK 7 !
I really want to use my Eclipse with JDK 8, but ONLY the Eclipse
How does Eclipse influence the export process? My target platform points to eclipse, but has JDK 7 set on it.
You can try to put a JRE 7 in your product location and test if it runs, remove the entry in the .ini file.
plugins
configurations
jre
...
If this works, your entry in the .ini file is probably wrong.
Another thought: "I've also included the JavaFX JAR", where did you include it? Maybe you need to include it in the JRE.

How to make a runnable jar for an application that uses JavaFX without native installers

I have a application that worked just fine to be run with "java -jar blah.jar" after exporting as a runnable jar from Eclipse and letting it "Package required libraries into generated JAR".
I added some JavaFX code to pop up a web browser. Now it seems it is impossible to make a runnable jar that works across minor Java versions. When I export it as a runnable jar, it copies in jfxrt.jar that is specific to my minor version. If I run this jar using "java -jar blah.jar" for the exact matching java version (jdk1.7.0_17) then it works fine, but if I use one slightly newer (jdk1.7.0_45) then it fails to resolve swingx classes properly. So much for "write once run anywhere".
I tried to use the JavaFX ant tasks but I can't get the task to actually package up the dependent jars. This doesn't actually include the fx:resources jars in the jar it creates, like the magic eclipse "package required libraries into generated JAR" does perfectly:
<fx:jar destfile="${dist}/${dist.jar}">
<fx:application id="BlahTesterApp"
mainClass="blah.MainClass"
toolkit="swing"/>
<fileset dir="${build}"/>
<fx:resources>
<fx:fileset dir="${lib}" includes="**/*.jar" />
</fx:resources>
<manifest>
<attribute name="Implementation-Vendor" value="My Team"/>
<attribute name="Implementation-Title" value="Tester App"/>
</manifest>
</fx:jar>
And seems to only be able to create "native bundles" which I don't want. I don't want to make users install an rpm or a deb when they used to just be able to run the darn jar.
I don't understand why Oracle had to introduce its own magical extra layer of deployment complexity here. Don't they want people to USE JavaFX?
For details on creating an executable single jar with JavaFX components, see:
Maven Shade JavaFX runtime components are missing
Update, December 2019
The answer to this topic evolves and changes over time, making the original answer and advice obsolete.
Review the current documentation at https://openjfx.io to see the latest best practices for packaging JavaFX applications.
Also review the packaging info in the JavaFX tag.
I tried to use the JavaFX ant tasks but I can't get the task to actually package up the dependent jars ... And seems to only be able to create "native bundles" which I don't want.
First, for most readers, it will be better to create a package for distribution based on jlink or jpackage rather than a single jar file.
If you really need a cross-platform single jar file, the current advice from openjfx.io is to use Maven or Gradle rather than Ant as a build tool.
Use the features of those build tools (e.g. the Maven Shade plug-in) to package your dependent jars with your code into an uber-jar.
When doing this, if you want the resultant jar to be cross platform capable, e.g. to work on Window+Mac+Linux, then you need to package all of the cross platform jars as dependencies into the uber-jar (use the appropriate JavaFX version for your project). You also need to supply a launcher main class which does not subclass Application.
<dependencies>
...
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13</version>
<classifier>mac</classifier>
</dependency>
</dependencies>
The resultant jar will require a more recent Java version to work (e.g. Java 11+).
Outdated info from an earlier update: ignore if using a modern JavaFX distribution
There is currently an incubating project (JEP 343: Packaging Tool), targeted for Java 14, with the following goals (these are different than what is required in the question, as the packaging tool is for creating native installers, which is specifically what the question doesn't want to do):
Create a simple packaging tool, based on the JavaFX javapackager tool, that:
Supports native packaging formats to give end users a natural installation experience. These formats include msi and exe on Windows, pkg and dmg on macOS, and deb and rpm on Linux.
Allows launch-time parameters to be specified at packaging time.
Can be invoked directly, from the command line, or programmatically, via the ToolProvider API.
https://openjdk.java.net/jeps/343 (link to packaging project wiki page).
The proposed project exists because:
To address these requirements previously, a packaging tool called javapackager was distributed with Oracle’s JDK 8. However, it was removed from Oracle’s JDK 11 as part of the removal of JavaFX.
Note, due to the update outlined above, until Java 14 is released, some of the packaging recommendations mentioned below (such as javafxpackager) only apply to, now-outdated, older Java distributions (8-10).
Also the advice on not to include Java Platform libraries is outdated. From Oracle Java 8 until Oracle Java 10, JavaFX was included in the base JRE (Java runtime environment). From Java 11 on, JavaFX is not include in the base JRE and, indeed, the platform libraries must be added to the Java module path separately. Again, review https://openjfx.io for packaging options for JavaFX applications.
Outdated info from original answer: ignore if using a modern JavaFX distribution
JavaFX packaging alternatives
Follow the e(fx)clipse tutorial for creating an executable jar file for a JavaFX application using Eclipse.
The Oracle java packaging ant tasks and javafxpackager tool can create executable jars (described in the Oracle documentation as standalone applications). If you cannot generate such jars using the tools, then you are likely not using the tools correctly.
Require a minimum version of Java 8, where jfxrt.jar (i.e. the JavaFX classes) is on the boot class path.
Use a 3rd party build tool chain such as the JavaFX Maven plugin or the JavaFX Gradle plugin.
Alternative (1), e(fx)clipse packaging, is recommended for you since you are using Eclipse.
Advice (outdated)
Never try to include Java platform libraries (such as jfxrt.jar) with your application. No guide you find on the internet should ever instruct you to do such a thing (due to the obvious incompatibility between minor version issues you outlined in your question). The only exception to this rule would be if you are building a self-contained, native installed application that doesn't rely on a pre-installed JRE (which you aren't).

JavaFX: Unable to include JavaFX runtime in classpath

I am developing a JavaFX application, working on Java 1.7(build 1.7.0_25-b17). Hence I assumed that javafx runtime was included in the java runtime. The project has some dependencies and those are defined in the pom.xml file.
The problem I have at hand is that the javafx runtime(jfxrt.jar) does not seem included in the class path as shown above. Due to this, my application shows compile errors pointing to javafx classes. Is there anything I am missing.
The maven dependencies are show below:
I added the javafx runtime separately to the pom as below and it worked:
<dependency>
<groupId>javafx</groupId>
<artifactId>jfxrt</artifactId>
<version>${javafx.min.version}</version>
<scope>system</scope>
<systemPath>${java.home}\lib\jfxrt.jar</systemPath>
</dependency>
From What is JavaFX?:
JavaFX 2.2 and later releases are fully integrated with the Java SE 7 Runtime Environment (JRE) and the Java Development Kit (JDK).
This means you should be able to just use the javafx.* packages without adding any library besides the JDK. It seems that Eclipse and Maven are being stupid in your case. (The JavaFX library and a bunch of others are in $JDK_HOME/jre/lib/*, Eclipse only seems to add what's in $JDK_HOME/lib. IntelliJ IDEA does the right thing here.)
JavaFX in Java7 is not on any classpath - you need to adjust your project classpath or use a tool like e(fx)clipse which manages that for you.
In Java8 it is on the extension classpath!

javafx is not recognized after installing jdk 7u9

I installed jdk 7u9 and added it to the build path of an eclipse Java project.
However, when I'm trying to import some javafx classes eclipse can't recognize them:
import javafx.scene.media.Media;
I read at Oracle's website (and a lot of other websites) that javafx is already included in jdk 7u9 and there is no need to install any additional addons.
What could be the problem?
The jfxrt.jar is in the jre/lib folder of your jdk, but not on the default boot classpath. That is why Eclipse won't add it to the "JRE System libraries".
The issue is tracked here.
The fix will be made in Java 8.
You should add the jar manually to the project build path or use e(fx)clipse and setup a JavaFX Project.

Categories