Maven can't find JavaFX - java

Build Failure on Maven:
package javafx.application does not exist
I'm using JDK 8 because JDK 11 doesn't have JavaFX included by default.
I have openjfx listed in my pom file as a dependency.
I have JAVA_HOME set to:
$JAVA_HOME
bash: /usr/lib/jvm/java-8-openjdk-amd64: Is a directory
Is there an environment variable that needs to be set in order for Maven to find the JavaFX jars?
here is the terminal output and pom file

You are trying to use files compiled for version 54 (which is Java 10 according to https://en.wikipedia.org/wiki/Java_class_file#General_layout) and the Java 8 you are using does not understand any higher versions than 52.
You cannot use this javafx-base artifact with Java 8. Either revise your code or upgrade to at least Java 10.

Your Maven still use JDK 11.
Try Oracle JDK 8 for Linux https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html or you can install from software repos in Linux.
Try to remove, uninstall all things of JDK 11 (then check environment variables carefully, checking by command java -version and javac -version to be sure you are using JDK 8).
Clean (mvn clean) and re-build project.

Related

How to use JFX/OpenFX with OpenJDK 8

Is there any javafx/OpenJFX dependency which can be used directly in the pom file so that it works with OpenJDK 8? Or any workaround (without installing anything) which works with OpenJDK 8?
I have gone through a lot of similar questions on SO, but the solution to use JFX/OpenFX with OpenJDK 8 is either to install the openjfx package in Ubuntu OR use Oracle JDK 8. Unfortunately I cannot do both. I am using OpenJDK 8 and need to use javafx/OpenJFX within my swing application. The OpenJDK does not contain jfxrt.jar in its ext folder (as in case of Oracle JDK 8), and the versions of OpenJFX start from Java 9/10. And on trying to compile I get
class file has wrong version 54.0, should be 52.0 which is expected as it is build with Java 10
Any leads would be really helpful. Thanks!
I have already gone through the below links
Why is JavaFX is not included in OpenJDK 8 on Ubuntu Wily (15.10)?
"class file has wrong version 54.0, should be 52.0" while trying to build JavaFX application
"class file has wrong version 54.0, should be 52.0" while compiling javaFX project
How to find out JavaFX version
Is there any javafx/OpenJFX dependency which can be used directly in the pom file so that it works with OpenJDK 8?
AFAIK, no. There are org.openjfx artifacts for OpenJFX 11 onwards, but they won't work with Java 8. (The class file version will be wrong.)
Or any workaround (without installing anything) which works with OpenJDK 8?
I think you will need to build your own copy of OpenJFX from source, and (touch wood) "package it" with your application1.
(The following is purely based on reading the OpenJFX build instructions. I have not tried this out.)
So if you want to build a stand-alone OpenJFX 8 for use with OpenJDK 8, then you should try the following build instructions on the OpenJFX wiki:
Building OpenJFX 8u
The result of the build is (apparently) a ZIP file that is designed to be "overlayed" onto a JRE installation.
You may be able to repackage that into JARs and native libraries that you can include in your application.
For OpenJFX 9 and later, the build instructions are here:
Building OpenJFX
Apparently, for N >= 9, OpenJFX version N is supposed to be supported for OpenJDK N and OpenJDK N - 1. So if that is accurate, you should be able to build OpenJFX 9 for OpenJDK 8. On the other hand, the build instructions talk about generating modules, and module support is only available in Java 9 and later. However it is still worth a try (IMO).
1 - Options include 1) creating a custom Debian package(s) (or RPMs) ... analogous to the existing Ubuntu packages, 2) incorporating the relevant classes and native libraries into your application JAR, or 3) adding them to your applications classpath and library load path. You may need to experiment.
Why don't you just use, e.g., https://bell-sw.com/pages/downloads/#/java-8-lts and download the full Java version (not standard). It should already contain JavaFX and is one of the many OpenJDK 8 versions floating arround.

How can I switch java verisons in intelliJ?

I'm using the linux beta installation on my chrome-book, and I'm trying to set up a project to use the jdk version 1.8. I previously had a project set up that uses jdk 1.11, and now it seems that even though the current project is configured to use jdk 1.8 in project settings etc, the maven installation used by intellij is still configured to use jdk 1.11. When I run java -version and mvn -verison in the intelliJ terminal, java 11 turns up. I tried changing the maven settings as well, but whenever I try to mvn compile and install, I get the following error:
/usr/lib/jvm/jdk1.8.0_271/bin/java: 1: /usr/lib/jvm/jdk1.8.0_271/bin/java: Syntax error: "(" unexpected
I can't figure out why this is happening, but it must be the fact that maven thinks this is java 11, when it's java 8. Does anyone know how to fix this?
CTRL-ALT-SHIFT-S / Project / Project SDK - you can choose existing or add configure another one
It turns out I had downloaded jdk-8u271-linux-arm64.tar.gz instead of jdk-8u271-linux-x64.tar.gz, which is why the code wasn't recognized after installing the jdk. Apparently the two are designed for different CPU architectures, and arm is for mobile devices, and wasn't compatible with my chromebook.

General error during semantic analysis: Unsupported class file major version 57

I'm trying to setup libgdx for a desktop game and when I try to generate the project I have this error and the build fails.
I've the latest versions of Java(13.0.2) and Gradle(6.6), both set as environment variables in the path. Can somebody help me?
The error looks like this:
Could not compile settings file 'C:\Users\noemi\Desktop\Test\settings.gradle'.
> startup failed:
General error during semantic analysis: Unsupported class file major version 57
java.lang.IllegalArgumentException: Unsupported class file major version 57
This is not a LibGDX issue. Gradle 5 is incompatible with Java 13. You either need to update Gradle (the wrapped version in your project) to Gradle 6 or later, or you need to use a lower version of the JRE.
To update the wrapped gradle, go to gradle/wrapper/gradle-wrapper-properties in your project and update the version number. I'm using 6.1.1.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
If you have an older LibGDX project, you might have to modify the build.gradle file in the android module to be compatible with Gradle 6. You can copy-paste to replace the copyAndroidNatives task with the one here.
startup failed:
General error during semantic analysis: Unsupported class file major version 61
how to fix this react native issues
JAVA JDK 17
Go to the android/ directory of your react-native project
Create a file called local.properties with this line:
sdk.dir=C:\Android\sdk
GOTO
android\gradle\wrapper\gradle-wrapper.properties
CHANGE
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
TO
distributionUrl=https://services.gradle.org/distributions/gradle-7.3-all.zip
GOTO
android\gradle.properties
add this line
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
This problem occurred when I run my old Flutter project that I coded 2 years ago. I think with Android project will also fix in the same way. I'm use MacOS and Android Studio Bumblebee.
First, need to move to the android folder and check gradle version:
cd android
./gradlew --version
It show Gradle version 6.7.1 and you need attention to the JVM line, and my JDK version is 15.0.2. It is too new for this project. So you must to downgrading from open jdk version to old version or upgrade Gradle version in gradle/wrapper/gradle-wrapper.properties to new version.
If you downgrade JDK version, you can download from this. In my case, I downgraded from Java SE 15 to Java SE 11.
After I open Android of Flutter project
Go to Preferences->Build, Execution, Deployment → Build Tools → Gradle → and choose JDK version 11.
Go to Build -> Clean Project -> Rebuild Project.
Go to Terminal run java --version, if it still show JE version 15 then You must set JAVA_HOME before.
You only need to add the following to your .bash_profile or .zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home
Save and go to android folder and run again
./gradlew --version
It will show JDK version 11 correct.
Finally, run flutter run.
If you're using eclipse, go to
Eclipse > Preferences > Gradle
Update Java home to point to Java home location
I have downgraded gradle file thats why this error happens so finally I have to change Gradle wrapper file From
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
Check gradle version and bundle version using the following link
Link https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
If you want to upgrade android/gradle/build.gradle change dependencies classpath 'com.android.tools.build:gradle:[latest version]'

exec-maven-plugin Java version different from maven-compiler-plugin Java version in NetBeans project

I start up the NetBeans IDE 12.0 with a system environment JAVA_HOME (1.8) lower than what the IDE uses (14). The IDE output window of Maven execution seems to show that the project is run with JAVA_HOME for JDK 14, running project files this way.
But the exec-maven-plugin fails with java.lang.UnsupportedClassVersionError: com/mycompany/Start has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
This seems to indicate that Maven runs under 1.8 in the IDE, ignoring the IDE's own override setting of JAVA_HOME of 14. It uses the JDK as set in JAVA_HOME, because if I set JAVA_HOME to 14.0 before IDE startup then it works.
I am looking for the correct way, the right places, to set the JDK for any project specifically, regardless of the JAVA_HOME setting that is active when the IDE starts.
My case can be reproduced by running the IDE 12.0 with JDK 14.0 installed, but with JAVA_HOME set to 1.8. before IDE startup. I use the Maven project generated from the command at https://wicket.apache.org/start/quickstart.html - all set to defaults. The file to run is Start.java.
This is important to me because I must open many different projects with different JDKs so it is not practical to re-start the IDE with different JAVA_HOME settings each time. As it is, it appears that my setting is poorly defined - I must be missing something.
I should add that in the project properties, I have set the Build|Compile|Java Platform to JDK 14 (Default) as expected.
I have filed a NetBeans Issue
For maven, if you want the byte code of your project to be 1.8, try just setting variables used by the compiler plugin even if you're using a newer JDK.
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
If you want a different java install completely, then you might want to look into the toolchains. But I'd only go this route if the above doesn't meet your needs.
https://maven.apache.org/guides/mini/guide-using-toolchains.html
I am not familiar with NetBeans but hopefully it will read the compiler level for maven.

UnsupportedClassVersionError on Gradle build with only JDK 11 installed?

Getting this error when trying to run gradle build.
org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Now there's tonnes of similiar questions on StackOverFlow about this, but every suggestion doesn't work that I've found:
My Project/Module language level are the same (11)
The bytecode version of the project is also 11
There is only OpenJDK11 installation I'm using.
Path and JAVA_HOME variables point to the above installation.
There are no other lingering java/oracle enviromental variables.
Running java -version results in:
I don't understand what's happening. I can't see how it's using JRE 8 when I only have JDK 11. I'm at a total loss here.
It may be that the Gradle JVM is still set incorrectly. If you are using IntelliJ, you can change this by going to File > Settings > Build, Execution, Deployment > Build Tools > Gradle and change Gradle JVM to 11 (or to the Project JDK).

Categories