java.lang.module.FindException: Module javafx.controls not found - java

I'm trying to run a JavaFX application in IntelliJ. Environment - Ubuntu 18.04. Java - 11.
But it gives me error saying :
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
Whole command in the run-console :
/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java --module-path
/home/mua/Software/javafx_sdk-1_3_1-b05a-linux-i586/javafx-sdk1.3/lib
--add-modules=javafx.controls,javafx.fxml -Djava.library.path=/home/mua/Software/javafx_sdk-1_3_1-b05a-linux-i586/javafx-sdk1.3/lib -javaagent:/home/mua/Software/ideaIU-2020.3.1/idea-IU-203.6682.168/lib/idea_rt.jar=41593:/home/mua/Software/ideaIU-2020.3.1/idea-IU-203.6682.168/bin
-Dfile.encoding=UTF-8 -classpath /home/mua/Desktop/PhotoSlide/PhotoSlide/target/classes:/home/mua/.m2/repository/org/openjfx/javafx-base/16-ea+7/javafx-base-16-ea+7.jar:/home/mua/.m2/repository/org/openjfx/javafx-base/16-ea+7/javafx-base-16-ea+7-linux.jar:/home/mua/.m2/repository/org/openjfx/javafx-fxml/16-ea+7/javafx-fxml-16-ea+7.jar:/home/mua/.m2/repository/org/openjfx/javafx-fxml/16-ea+7/javafx-fxml-16-ea+7-linux.jar:/home/mua/.m2/repository/org/openjfx/javafx-graphics/16-ea+7/javafx-graphics-16-ea+7.jar:/home/mua/.m2/repository/org/openjfx/javafx-graphics/16-ea+7/javafx-graphics-16-ea+7-linux.jar:/home/mua/.m2/repository/org/openjfx/javafx-media/16-ea+7/javafx-media-16-ea+7.jar:/home/mua/.m2/repository/org/openjfx/javafx-media/16-ea+7/javafx-media-16-ea+7-linux.jar:/home/mua/.m2/repository/org/openjfx/javafx-controls/16-ea+7/javafx-controls-16-ea+7.jar:/home/mua/.m2/repository/org/openjfx/javafx-controls/16-ea+7/javafx-controls-16-ea+7-linux.jar:/home/mua/.m2/repository/org/openjfx/javafx-swing/16-ea+7/javafx-swing-16-ea+7.jar:/home/mua/.m2/repository/org/openjfx/javafx-swing/16-ea+7/javafx-swing-16-ea+7-linux.jar:/home/mua/.m2/repository/org/controlsfx/controlsfx/11.0.2/controlsfx-11.0.2.jar:/home/mua/.m2/repository/org/kordamp/ikonli/ikonli-core/12.1.0/ikonli-core-12.1.0.jar:/home/mua/.m2/repository/org/kordamp/ikonli/ikonli-javafx/12.1.0/ikonli-javafx-12.1.0.jar:/home/mua/.m2/repository/org/kordamp/ikonli/ikonli-themify-pack/12.1.0/ikonli-themify-pack-12.1.0.jar:/home/mua/.m2/repository/org/kordamp/ikonli/ikonli-fontawesome-pack/12.1.0/ikonli-fontawesome-pack-12.1.0.jar:/home/mua/.m2/repository/com/github/dragon66/icafe/1.1-SNAPSHOT/icafe-1.1-20190902.150913-102.jar:/home/mua/.m2/repository/com/github/jai-imageio/jai-imageio-core/1.4.0/jai-imageio-core-1.4.0.jar:/home/mua/.m2/repository/com/twelvemonkeys/imageio/imageio-core/3.6/imageio-core-3.6.jar:/home/mua/.m2/repository/com/twelvemonkeys/common/common-lang/3.6/common-lang-3.6.jar:/home/mua/.m2/repository/com/twelvemonkeys/common/common-io/3.6/common-io-3.6.jar:/home/mua/.m2/repository/com/twelvemonkeys/common/common-image/3.6/common-image-3.6.jar:/home/mua/.m2/repository/com/twelvemonkeys/imageio/imageio-tiff/3.6/imageio-tiff-3.6.jar:/home/mua/.m2/repository/com/twelvemonkeys/imageio/imageio-psd/3.6/imageio-psd-3.6.jar:/home/mua/.m2/repository/com/twelvemonkeys/imageio/imageio-metadata/3.6/imageio-metadata-3.6.jar:/home/mua/.m2/repository/org/slf4j/slf4j-simple/2.0.0-alpha1/slf4j-simple-2.0.0-alpha1.jar:/home/mua/.m2/repository/org/slf4j/slf4j-api/2.0.0-alpha1/slf4j-api-2.0.0-alpha1.jar:/home/mua/.m2/repository/com/h2database/h2/1.4.200/h2-1.4.200.jar:/home/mua/.m2/repository/org/ejml/ejml-simple/0.40/ejml-simple-0.40.jar:/home/mua/.m2/repository/org/ejml/ejml-core/0.40/ejml-core-0.40.jar:/home/mua/.m2/repository/javax/media/jai/com.springsource.javax.media.jai.core/1.1.3/com.springsource.javax.media.jai.core-1.1.3.jar:/home/mua/.m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar:/home/mua/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.12.0/jackson-databind-2.12.0.jar:/home/mua/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.12.0/jackson-annotations-2.12.0.jar:/home/mua/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.12.0/jackson-core-2.12.0.jar
org.photoslide.App
And I've added the VM with :
--module-path /home/mua/Software/javafx_sdk-1_3_1-b05a-linux-i586/javafx-sdk1.3/lib --add-modules=javafx.controls,javafx.fxml
And added libraries too :
Source code : https://github.com/maifeeulasad/PhotoSlide
Java configurations :
>>java --version
openjdk 11.0.10 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)
>>javac --version
javac 11.0.10

From what I understand, you're using Non-modular with Maven.
I built one from scratch myself following the instructions provided in the link above and noticed the picture marked in yellow.
There are 2 Environment Virables that need to be set for the OpenJDK. One in your system (e.g. ./bashrc file) and one in IntelliJ for Maven (in case you're using Java 11 or above, which you are in this case).
As per your post, I know you have the one in your system, but it doesn't mention the one in this picture, so make sure you do.
Also, notice I haven't set up any VM options!
The link above states:
The JavaFX classes will be recognized. Notice also that Maven manages
the required dependencies: it will add javafx.base and
javafx.graphics that are required by javafx.controls and
javafx.fxml, but most important, it will add the required classifier
based on your platform, downloading the specific platform jars.
This is my pom.xml file (auto-generated by IntelliJ when making the project):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>testing_maven</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>com.company.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I strongly recommend looking through the link I posted. You might've missed something. If not, then definitely try and create a new testing project, follow the instructions and see if it works. If it does, compare things to your current project.
Sorry, I couldn't have been of more help. I don't really work with Maven.

Related

Build failing due to version only via terminal

I have a simple maven project which builds fine and runs in Intellij. The Java version is set to version 8 under relevant settings in Intellij.
Under the maven POM file, I have set the following to point to the java version.
<modelVersion>4.0.0</modelVersion>
<properties>
<java.version>1.8</java.version>
<javac.src.version>1.8</javac.src.version>
<javac.target.version>1.8</javac.target.version>
</properties>
<groupId>org.example</groupId>
<artifactId>exa</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
.....
My maven version and info as follows:
Maven home: C:\Users\name\apache-maven-3.6.3\bin\..
Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_231\jre
As mentioned, no issues when run via Intellij. But when I run maven commands via the intellij terminal or normal terminal, I get following error.
Example Maven commands.
mvn clean package
or
mvn verify
Error:
COMPILATION ERROR
/C:/Users/name/projectname/src/main/java/pack/Main.java:[17,51] method references are not supported in -source 1.5
I don't even have java sdk 1.5 on my machine. Can I get some help on where I should change this version to 8 so I can make a maven build please? Thanks.
In your project's pom.xml, it seems the source is configured to java 1.5. Make sure the correct source version is configured in pom.xml.
If you are using maven-compiler-plugin, change the version as below.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
or
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

Configure Maven to allow a range of JREs

I am teaching a 2nd semester Java course, and I am trying to set up a simple Maven project that will will run in any student's environment (Windows/Mac/Linux, IntelliJ/VS Code/Eclipse, any version of Java 8 or above) without complaining. Because this is only a second semester programming course, I want pom.xml to be as simple as possible. The project need only be a couple of Java source files and a couple of test files.
The current pom.xml is below. It works, but Visual Studio Code on MacOS with Java 8 generates the following warnings:
Build path specifies execution environment J2SE-1.5. There are no
JREs installed in the workspace that are strictly compatible with
this environment.
The compiler compliance specified is 1.5 but a JRE
1.8 is used
I can fix the problem by adding these lines:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
But, won't that cause warnings or errors for students with different Java versions? Since we aren't doing anything fancy, I don't want to require that they all use Java 12 or 13. Any version 8 or above is fine.
I also hesitate to tell the students to edit the properties above to match their machines because I assume that will cause problems if I pull their code and try to run it on my machine.
Is there a way to configure Maven and the IDE to simply be happy with any JDK version 8 and above?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gvsucis</groupId>
<artifactId>ArrayLab</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ArrayLab</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
You need to distinguish between the JDK and the Java version you build for.
Setting maven.compiler.source and maven.compiler.target only sets the target Java version. If you set it to 1.8, then you can build with any JDK that supports this, which are JDK 8 and above.
Please change your java home to use jdk not jre.
if you are using a jdk8+, then your pom configuration should work.
Typically all IDE refer the JAVA_HOME environment variable to find the java binary. So, Set your JAVA_HOME to jdk8+.
if it is widows machine restart is required otherwise just run source .bashrc or source .bach_profile

How to build a project and load the SDK with maven

I have to create a pom.xml, which builds the entire project. But it won't load the SDK.
I tried to include dependencies, but it didn't work.
<modelVersion>4.0.0</modelVersion>
<groupId>de.swp18gi.zugumzugeuropa</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ZugUmZug</name>
<description>Zug um Zug Europa</description>
</dependencies>
<properties>
<java.version>10</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<debug>false</debug>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>client</module>
<module>common</module>
<module>server</module>
</modules>
It is given like the below :
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Please reformat your pom.xml . Reference URL : https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
Forking out the java compiler does not mean that Maven does any work in locating an appropriate JVM for you.
My guess is that you want Maven to use a JDK including the compiler instead of the standard JRE the java command installed by default under Windows belong to.
The correct way to do this is to tell Maven which JDK-JVM to use (or - for advanced users - to tell it to use the Eclipse compiler)
You can either do it by setting the JAVA_HOME environment variable to point to an appropriate JDK you have downloaded and installed (these days Oracle only wants paying users so the Zulu version of OpenJDK is a suitable alternative - https://www.azul.com/downloads/zulu/) or by providing the full path to the javac you want to use in the <executable> tag. See https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#executable for full details.

Running Java 9 jshell in Eclipse [duplicate]

As Java 9 introduced the concept of JShell which enables us to write code without creating a class and a method, is it possible to use this feature of Java 9 in eclipse ?
You can use the TM Terminal to run JShell in Eclipse:
If necessary, install TM Terminal (contained only in some Eclipse packages)
Open a 'Terminal' view in Eclipse: Window > Show View > Other...: Terminal > Terminal
Launch a new Local Terminal
Run JShell, e. g. on Windows type "C:\Program Files\Java\jdk-9\bin\jshell" -v followed by Enter
Alternatively, you can use a Scrapbook Page, a built-in feature of the Eclipse Java IDE and which also works with older Java versions. You will have code completion and you can use Java classes of your project:
If this is not a feature ask for Eclipse, a very basic stub that you can come up with is:
public static void main(String[] args) throws Exception {
jdk.jshell.tool.JavaShellToolBuilder.builder().run();
}
When you execute this, you can further use your debug console as JShell in your IDE.
Sample screenshot:
If you like to use JShell (from Eclipse or from a Terminal) to try out code, a very nice option is to use the Maven JShell plugin and just run mvn from a corresponding (dummy) project (in Eclipse: Right-Click on the Project and Run As -> Maven build).
In that case JShell knows all the libraries specified in the dependencies of the project.
I am use this here: http://www.finmath.net/finmath-experiments/montecarlo-blackscholes/
A small pom.xml using some libraries (JavaFX, Apache commons, finmath lib) could look like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.finmath</groupId>
<artifactId>finmath-experiments</artifactId>
<version>0.1.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean install jshell:run</defaultGoal>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.johnpoth</groupId>
<artifactId>jshell-maven-plugin</artifactId>
<version>1.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<!-- Java FX -->
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-base -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11</version>
</dependency>
<!-- finmath-lib -->
<dependency>
<groupId>net.finmath</groupId>
<artifactId>finmath-lib</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>net.finmath</groupId>
<artifactId>finmath-lib-plot-extensions</artifactId>
<version>0.3.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
</project>
Note: Personally I prefer running this from a Terminal in macOS, since JShell supports "TAB-auto-completion" there, which appears to be missing when running from Eclipse.
There are multiple ways to do this as explained in other answers. But I would like to tell you a plugin which will provide more feature than just starting a normal JShell from Eclipse.
Check this Eclipse plugin QuickShell
This plugin will start JShell in Eclipse terminal. Like this:
You can also select your existing java source code and run it as a JShell script. For example :
.jsh and .jpage files can be run from Eclipse directly.
PS: I am author of this plugin.

Is it possible to use sysout without class and main method in Eclipse IDE using Java 9?

As Java 9 introduced the concept of JShell which enables us to write code without creating a class and a method, is it possible to use this feature of Java 9 in eclipse ?
You can use the TM Terminal to run JShell in Eclipse:
If necessary, install TM Terminal (contained only in some Eclipse packages)
Open a 'Terminal' view in Eclipse: Window > Show View > Other...: Terminal > Terminal
Launch a new Local Terminal
Run JShell, e. g. on Windows type "C:\Program Files\Java\jdk-9\bin\jshell" -v followed by Enter
Alternatively, you can use a Scrapbook Page, a built-in feature of the Eclipse Java IDE and which also works with older Java versions. You will have code completion and you can use Java classes of your project:
If this is not a feature ask for Eclipse, a very basic stub that you can come up with is:
public static void main(String[] args) throws Exception {
jdk.jshell.tool.JavaShellToolBuilder.builder().run();
}
When you execute this, you can further use your debug console as JShell in your IDE.
Sample screenshot:
If you like to use JShell (from Eclipse or from a Terminal) to try out code, a very nice option is to use the Maven JShell plugin and just run mvn from a corresponding (dummy) project (in Eclipse: Right-Click on the Project and Run As -> Maven build).
In that case JShell knows all the libraries specified in the dependencies of the project.
I am use this here: http://www.finmath.net/finmath-experiments/montecarlo-blackscholes/
A small pom.xml using some libraries (JavaFX, Apache commons, finmath lib) could look like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.finmath</groupId>
<artifactId>finmath-experiments</artifactId>
<version>0.1.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean install jshell:run</defaultGoal>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.johnpoth</groupId>
<artifactId>jshell-maven-plugin</artifactId>
<version>1.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<!-- Java FX -->
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-base -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11</version>
</dependency>
<!-- finmath-lib -->
<dependency>
<groupId>net.finmath</groupId>
<artifactId>finmath-lib</artifactId>
<version>5.0.2</version>
</dependency>
<dependency>
<groupId>net.finmath</groupId>
<artifactId>finmath-lib-plot-extensions</artifactId>
<version>0.3.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
</project>
Note: Personally I prefer running this from a Terminal in macOS, since JShell supports "TAB-auto-completion" there, which appears to be missing when running from Eclipse.
There are multiple ways to do this as explained in other answers. But I would like to tell you a plugin which will provide more feature than just starting a normal JShell from Eclipse.
Check this Eclipse plugin QuickShell
This plugin will start JShell in Eclipse terminal. Like this:
You can also select your existing java source code and run it as a JShell script. For example :
.jsh and .jpage files can be run from Eclipse directly.
PS: I am author of this plugin.

Categories

Resources