Prepare the environment for java11 and javaFx with Ubuntu 18.4

environment

ubuntu

___@kubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic

If you put java, it will be like this

___@kubuntu:~$ java --version
opensdk 11.0.1 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

___@kubuntu:~$ javac --version
javac 11.0.1

Install openjdk

As of November 18, 2018, if you install openjdk-11-jdk with apt, openjdk10 will be installed. It seems to switch in the future

This time install java11 using sdkman

  1. You can install sdkman just by following https://sdkman.io/install
  2. You can install java11 just by following https://sdkman.io/sdks
  3. Check with java --version and javac --version

The main body of java when installed with sdkman

/home/username/.sdkman/candidates/java/11.0.1-open

It is in

Write the path here when specifying jdk in Intellij etc.

Download javaFx

  1. Download from https://openjfx.io/

This time I decided to place it in / opt

/opt/openjfx-11.0.1_linux-x64_bin-sdk/
└── javafx-sdk-11.0.1
    ├── legal
    ...Abbreviation
    └── lib
    ...Abbreviation

Run with intellij

Create a javafx project

How to make it with reference to others

Setting that does not use gradle this time

  1. Write the code appropriately. Some sample is fine intelij_sample.png

  2. Press [Main ▼] on the upper left to open edit configurations

  3. Write settings such as jdk editconfig.png

  4. Set the VM Option as follows vmoption.png

--module-path=/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib
--add-modules=javafx.controls
--add-modules=javafx.swing
--add-modules=javafx.base
--add-modules=javafx.fxml
--add-modules=javafx.media
--add-modules=javafx.web
  1. Press OK
  2. Execute with Shift + F10

Addictive point

If you search normally on the net, there are many articles that contain only javafx.controls, which is incomplete, In that state, the following exception will appear, so include all modules cannotexecute.png

/home/___/.sdkman/candidates/java/11.0.1-open/bin/java -Djava.library.path=/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib --module-path=/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib --add-modules=javafx.controls -javaagent:/home/___/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/182.5107.16/lib/idea_rt.jar=43339:/home/___/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/182.5107.16/bin -Dfile.encoding=UTF-8 -classpath /home/___/sandbox/javafxtry/out/production/javafxtry:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/src.zip:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/javafx-swt.jar:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/javafx.web.jar:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/javafx.base.jar:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/javafx.fxml.jar:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/javafx.media.jar:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/javafx.swing.jar:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/javafx.controls.jar:/opt/openjfx-11.0.1_linux-x64_bin-sdk/javafx-sdk-11.0.1/lib/javafx.graphics.jar sample.Main
Exception in Application start method
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x2f837822) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x2f837822
	at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
	at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
	at sample.Main.start(Main.java:13)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
	at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
	at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
	... 1 more
Exception running application sample.Main

Process finished with exit code 1

Recommended Posts

Prepare the environment for java11 and javaFx with Ubuntu 18.4
Prepare a scraping environment with Docker and Java
Prepare the environment for CUDA, Nvida-Driver, and cuDNN on an Ubuntu 18.04 PC equipped with Geforce RTX2080 SUPER.
Prepare Java development environment with Atom
Prepare Java development environment with VS Code
Prepare the format environment with "Rails" (VScode)
Prepare the JVM language development environment with WSL
[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
Prepare the environment of CentOS 8 with Sakura VPS
Build Apache and Tomcat environment with Docker. By the way, Maven & Java cooperation
Rewrite the code for java.io.File with java.nio.Path and java.nio.Files
[Java] Environment construction procedure for developing struts 1.3 with Eclipse
What Java engineers need to prepare for the Java 11 release
Java + Spring development environment construction with VirtualBox + Ubuntu (Xfce4)
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
Prepare Python3 environment with CentOS7
JavaFX environment construction in Java 13
Java while and for statements
Store in Java 2D map and turn with for statement
Deploying a Java environment with Windows Subsystem for Linux (WSL)
Find the address class and address type from the IP address with Java
Getting started with Java and creating an AsciiDoc editor with JavaFX
Change the injection target for each environment with Spring Boot 2
Beginners install docker for mac and prepare php7.0 operating environment
[Java] Check the difference between orElse and orElseGet with IntStream
Change the setting value for each environment with Digdag (RubyOnRails)
Find the greatest common divisor and least common multiple with JAVA
Java sets the background color and background image for PowerPoint documents
Building an environment for creating apps with Rails and Vue
Access Web API on Android with Get and process Json (Java for the time being)
Use java with MSYS and Cygwin
Distributed tracing with OpenCensus and Java
Install Java and Tomcat with Ansible
Let's create Ubuntu environment with vmware
AWS SDK for Java 1.11.x and 2.x
Environment construction with Docker for beginners
Java for beginners, expressions and operators 1
Use JDBC with Java and Scala.
Java for beginners, expressions and operators 2
About the current development environment (Java 8)
Until you build the docker environment and start / stop the Ubuntu container
Build Java development environment (for Mac)
Follow the link with Selenium (Java)
Output PDF and TIFF with Java 8
How to install the language used in Ubuntu and how to build the environment
Look through Java and MySQL PATH with environment variables [Windows version]
Enable Java 8 and Java 11 SDKs on Ubuntu
Drag and drop files with JavaFX
[Java & SpringBoot] Environment Construction for Mac
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS
Creating a dual boot environment for Ubuntu Server 20.04.1 LTS and Windows 10
Classes and instances Java for beginners
Encrypt with Java and decrypt with C #
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
Find the address class and address type from the IP address with Java [No. 2 decoction]
For the time being, run the war file delivered in Java with Docker
Wait for PostgreSQL to start with Docker and then start the WEB service
[First Java] Make something that works with Intellij for the time being
[Java] Create a jar file with both compressed and uncompressed with the jar command
Creating a java web application development environment with docker for mac part1
Put Zabbix in Ubuntu with Docker and monitor Docker on the same host