JavaFX: Unable to include JavaFX runtime in classpath - java

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!

Related

Java 11 Methods are not recognised in IntelliJ even after importing them correctly

I have started a new Java 11 Project with the newest Version of the IntelliJ IDEA Community Edition (IntelliJ IDEA 2018.3.5).
Everything seemed to work just fine for a while, but then some MethodCalls from imported modules were not recognised without any obvious reason. I've already tried invalidating the cache, but it did nothing. I'm also using maven 3.6.0 as I stumbled upon a post which suggested that the maven version that comes with said IDEA is not compatible with Java 11.
More specifically I tried using the method Optional.ofNullable() (same with of() or any other method of this class) which IntelliJ even proposed with AutoComplete. After auto-completion however IntelliJ seems to have forgotten it just now knew the method and proclaims: "Cannot find symbol: class ofNullable". The funny thing is: I can even Ctrl-Click Optional to be directed to the class and see that the method is actually there.
I'm at a loss. Has somebody experienced a similar problem?
I have solved this problem as follows for the Spring boot project with the Gradle build tool.
IntelliJ-Idea version should support Java-11.
Bigger scope to narrower scope
(IDE support --> Build tool --> Project setting --> Modules setting --> application run setting)
Add Java-11 SDK in Idea-IDE
Change Gradle JVM to Java-11
Change Project SDK and Language Level to Java-11
Change Module Language Level to Java-11
Change modules SDK to Java-11
Application run configuration to Java-11

What is a possible, handy way to build a project with Maven which uses an embedded JRE?

I want my program to be usable by systems which do not have a JRE preinstalled.
What I'm a little bit struggling with right now is how can I tell Maven to use an embedded JRE and not the system JRE? Right now to build my application I'm using the maven-assembly-plugin along with the maven-nativedependencies-plugin to resolve native dependencies and the maven-jar-plugin.
My understanding in theory is somewhat of the following:
Copy(?) JRE into my project folder (e.g. a folder with java8)
Zip everything up (Somehow included in my build process)
Tell Maven to use the included JRE
User can unpack and does not need a preinstalled JRE
I assume that I somehow need to tell maven/my application to unpack that shipped JRE and use it? I already read about the Java 9 Deployment guide (I'm using Java8 though) and jlink'ed images, however all of it seems a little bit tricky and I'm not build process expert.
Could anyone share their experiences / thoughts on that topic?
There are few ways to build an executable image:
If you are on Java 9 you can use jlink to build an executable runtime image.
Use launch4j tool to include JRE e.g. as shown in this answer.
Include JRE as a Maven dependency and repackage with assembly plugin. Do note that this dependency is quite outdated.
<dependency>
<groupId>com.oracle.java</groupId>
<artifactId>jre</artifactId>
<version>1.8.0_131</version>
</dependency>

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

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.

I'm getting Exception jniopencv_core.dll: Can't find dependent libraries error while trying Sikuli Java API test example

I want to test Sikuli Java API, to be specific http://code.google.com/p/sikuli-api/wiki/SikuliWebDriver . The dependency is added using maven, i.e.
<dependency>
<groupId>org.sikuli</groupId>
<artifactId>sikuli-webdriver</artifactId>
<version>1.0.1</version>
I'm using IntelliJ Idea 11 Community Edition on 64-bit Windows 7. 32-bit JDK 6 is used in project.
I tried to use maven dependencies out of box as it described on the project site (still remembering, that there should be some native .dll installation, which doesn't occure when we use maven depencdencies only). In runtime I've get Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\User\AppData\Local\Temp\javacpp26205597583997\jniopencv_core.dll: Can't find dependent libraries
Then I downloaded sikuli-r930-win32, installed it to C:\SikuliX. then added SIKULI_HOME system variable, setting path to C:\SikuliX. But still get the same error message in runtime.
Please, help! Just ideas what to check.
It was checked with http://DependencyWalker.com that opencv_core240.dll was lost (possibly, a common Windows 7 bug). After it was downloaded from https://code.google.com/p/myrobotlab/source/browse/trunk/myrobotlab/thirdParty/repo/net.sourceforge.opencv/opencv/2.4.0/x86.64.windows/opencv_core240.dll?r=711 and placed to C:\SikuliX\libs\ together with other .dlls, the problem was solved.

Installing and importing javafx on windows 7

I have installed jdk1.7.0_07 and changed PATH but i still cannot import javafx, is there something that i should do fix this?
Make sure that /jre/lib/jfxrt.jar is on your compile path.
For example for the 64 bit jdk7u6 version on win7, the jfxrt.jar is located here:
C:\Program Files\Java\jdk1.7.0_06\jre\lib\jfxrt.jar
jfxrt.jar was left off of the java runtime path on purpose for jdk1.7.0_06 until further testing between JavaFX and rest of the java infrastructure has been completed. This means that non-JavaFX programs cannot possibly be impacted by possible compatibility issues which may be caused by JavaFX. To date I have never encountered any compatibility issue - this was just a cautious move by Oracle in this regard I believe.
In a future release the jfxrt.jar should be added to the default compile and runtime classpath for Java and some of the information below should be irrelevant. You can track the request to add jfxrt.jar to the default java runtime.
Compiling and Running a JavaFX program from the command line
Example below is for a JavaFX application class named javafxsamples.AudioPlaylist
If you are compiling from a command line, compile with:
javac -cp ".;C:\Program Files\Java\jdk1.7.0_06\jre\lib\jfxrt.jar" javafxsamples/AudioPlaylist.java
To run from the command line, you can use:
java -cp ".;C:\Program Files\Java\jdk1.7.0_06\jre\lib\jfxrt.jar" javafxsamples.AudioPlaylist
Though, it is recommended that you package your applications with the javafxpackager, rather than manually adding jfxrt.jar to your classpath (javafxpackager packaged applications will embed a launcher which finds jfxrt.jar and adds it to the classpath for you).
javafxpackager -createjar -nocss2bin -appclass javafxsamples.AudioPlaylist -srcdir . -outfile AudioPlaylist.jar
After that you can run the app without needing to specify a jfxrt.jar location on the classpath:
java -jar AudioPlaylist.jar
Compiling and Running a JavaFX program using IDEs
NetBeans
If you are using NetBeans 7.2+, you can create a JavaFX project type and it should automatically find JavaFX jfxrt.jar and place it on your project's classpath when you set up jdk1.7.0_07 as your platform.
Eclipse
If you are using e(fx)clipse make sure you are using the latest version (0.0.14+) which is features better facilities for detecting JavaFX.
Idea
Intellij Idea 11.1.3 will automatically add all of the files from the jre lib directory to it's project classpath, so you shouldn't get compile errors with it. Note that Idea's behaviour is erroneous in this regard, it shouldn't really do this, but it in the end you end up with the expected behaviour of being able to compile and run your JavaFX classes from idea.
Building a JavaFX program using maven
Make the jfxrt.jar a system dependency for your maven project to get it on the path.
Use the maven antrunner to execute the javafx ant tasks for deployment packaging.
An example of packaging JavaFX with maven is provided in this maven project.
Even if you use an IDE or Maven for your build, it is still recommended, you package your app for delivery using the javafx ant tasks or javafxpackager utility as this should provide the most robust deployment solutions for your application.

Categories