Problem with JavaFX connection in intellij IDEA
Good afternoon,
I'm new to programming, got as far as learning JavaFX.
But there were some problems.
IDEA doesn't see no packages, no classes, no JavaFX methods.
I am also an Ubuntu user, and I have already performed the operation to install Java FX on linux
Sudo apt-get install openjfx
JDK is naturally installed, I tried to create a project using both Java and JavaFX -- useless. Screenshot attached
Thank you in advance
5 answers
0. install OpenJDK. Actually, there will be less problems
Install JavaFX: https://gluonhq.com/products/javafx/
In Idea add an external library to your project:
Ctrl+Shift+Alt+S: Project Settings -> Libraries -> + -> {select install/pass/to/JavaFX/javafx-sdk-11.0.2/lib}Be sure to add VM Option:
Run -> Edit Configurations -> Application -> {YourApp}:
Configuration -> VM options: --module-path ${PATH_TO_FX} --add-modules=javafx.controls,javafx.fxml,javafx.base
Where ${PATH_TO_FX} is your path to the JavaFX library (install/pass/to/JavaFX/javafx-sdk-11.0.2/lib)
Or write in Path Variables:
File -> Setings -> Appearance & Behavior -> Path Variables -> +:
Name = PATH_TO_FX, Value = install/pass/to/JavaFX/javafx-sdk-11.0.2/lib
- you can still install SceneBuilder: https://gluonhq.com/products/scene-builder/ , but this is optional
It's easier to really use maven or gradle, as pointed out in the comment.
Even if you are a novice, spend a little time studying them - and this will greatly simplify further training and development. With them, you do not need to install JavaFX or other dependencies separately, everything is done in the configuration file in a couple of lines.
Maven is simpler, and gradle is more complex, but there are much more features (for javafx with gradle, use not just dependencies, but plugins, google "javafx gradle plugin")
And in this case, as far as I remember the development without the wonderful maven/gradle, you need to open the project settings (ctrl-alt-shift-s) and in the libraries section add the installed javafx
If you still decide to do it through maven, then here is an excellent guide to starting it. If you don't want to use maven, you can download the JavaFX library from here, and then in connect it in the structure of the intellij idea project (I don't remember exactly how, but visually everything is clear there).
There are two options: 1) use maven and don't sweat it 2) Download OpenJFX (download OpenJFX https://gluonhq.com/products/javafx/) and read help https://openjfx.io/openjfx-docs/#install-javafx
I would rather advise you to deal with maven, since you were given a link to the lesson.
If very short: Idea-File-New-Project-Maven(select JDK and uncheck the archetype) - groupId: JavaFX, artifactId: sample Next - Finish.
When the project opens, you need to go to file POM.xml add
<dependencies>
<dependency>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
</dependency>
</dependencies>
IDEA will download the dependencies itself. Well, then you seem to know
Plan " A " - Specify the library in Run
Step#1:
Project Srtucture --> Modules -->
Path
(*) Inherit project compile output path
( ) Use module compile output path
Dependencies
|+| --> 2 Library --> Java --> ВЬІБРАТЬ РАСПОЛОЖЕНИЕ /lib
Step#2:
Run --> Edit Configuration -->
VM options:
COPY AND PASTE THE FOLLOWING INTO THE FIELD:
--module-path {ВЬІБРАТЬ РАСПОЛОЖЕНИЕ /lib} --add-modules javafx.controls,javafx.fxml
|OK|| ||Apply|
Plan " B " - Specify the module with the library in Run
Step#1:
Project Srtucture --> Modules -->
Path
( ) Inherit project compile output path
(*) Use module compile output path
Dependencies
|+| --> 2 Library --> Java --> ВЬІБРАТЬ РАСПОЛОЖЕНИЕ FX lib
Step#2:
File --> Settings --> Path Variables --> |+|
INSERT --> PATH_TO_FIX IN THE Name FIELD:
Add Variables
Name: PATH_TO_FX
Value: ВЬІБРАТЬ РАСПОЛОЖЕНИЕ /lib
|OK|| |
Step#3:
Run --> Edit Configuration --> VM options:
COPY AND PASTE TO FIELD NEXT:
--module-path $PATH_TO_FX$ --add-modules javafx.controls,javafx.fxml
** * CHARACTER DIFFERENCE:
$ - $Linux$ - $PATH_TO_FIX$
% - %Windows% - %PATH_TO_FIX%
MY right key-IDEA will fill in the SELECTED MODULE itself
|OK|| ||Apply|
PS. TO EXCLUDE ERRORS
USE:
Ctrl+C/Ctrl+V
ТОЛЬКО ОДНУ ВЕРСИЮ БИБЛИОТЕКИ FX
DO NOT MIX:
КОМПОНЕНТЬІ РАЗНЬІХ ВЕРСИЙ БИБЛИОТЕК FX