Eclipse JavaFX JDK 12 - bekomme mein Projekt nicht mehr compiliert

  • Themenstarter Themenstarter marlem
  • Beginndatum Beginndatum
M

marlem

Gast
Hallo,

Ich arbeite mit folgender Eclipse-Version:
Eclipse IDE for Java Developers
Version: 2019-06 (4.12.0)
Build id: 20190614-1200
OS: Windows 10, v.10.0, x86_64 / win32
Java version: 10.0.1

Ich habe mit JavaFX einen barrierefreien Texteditor entwickelt der unter JDK 10 compiliert hat und ausgeführt werden konnte.

Jetzt habe JDK 12 installiert und habe versucht mit Hilfe von diesem Youtube-Video:
JavaFX in Eclipse bereitzustellen so dass mein Texteditor wieder kompiliert.

Wenn ich jetzt das Projekt compiliere bekomme ich folgende Fehlermeldung:

Error: JavaFX runtime components are missing, and are required to run this application

Frage:
Was muss ich tun, damit mein Projekt wieder compiliert?
 
Also, die aktuelle Fehlermeldung habe ich behoben.
Die Lösung steht hier:
https://stackoverflow.com/questions...are-missing-javafx-11-and-openjdk-11-and-ecli

ich war also bei "Eigenschaften" vom Projekt -> "RUN/DEBUG SETTINGS", dann Doppelklick auf Main,
dann Register x= Arguments und hier bei VM arguments dass hier eintragen:
--module-path \" C:\Program Files\Java\javafx-sdk-11.0.2\legal" --add-modules javafx.controls,javafx.fxml

Leider compiliert das Projekt noch immer nicht, es gibt folgende Fehlermeldung:
Description Resource Path Location Type
The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project JTeditorFX Unknown Java Problem

hat jemand eine Idee was ich tun muss?
 
Hallo,

wenn ich mein Programm im Dosfenster compiliere dann hagelt es auch Fehlermeldungen:

Verzeichnis von C:\Projekte\Java\JTeditorFX\src

21.08.2019 21:17 <DIR> .
21.08.2019 21:17 <DIR> ..
21.08.2019 21:17 3.492 GermanModifierMenu.class
24.10.2019 16:57 1.330 GermanModifierMenu.java
22.08.2019 14:54 1.643 Main$1.class
22.08.2019 14:54 27.279 Main.class
23.10.2019 21:56 29.491 Main.java
12.07.2018 20:43 828 style.css
6 Datei(en), 64.063 Bytes
2 Verzeichnis(se), 733.687.037.952 Bytes frei

C:\Projekte\Java\JTeditorFX\src>javac Main.java
Main.java:33: error: package javafx.application does not exist
import javafx.application.Application;
^
Main.java:34: error: package javafx.beans.property does not exist
import javafx.beans.property.BooleanProperty;

^
Main.java:35: error: package javafx.beans.property does not exist
import javafx.beans.property.SimpleStringProperty;
^
Main.java:36: error: package javafx.beans.property does not exist
import javafx.beans.property.StringProperty;
^
Main.java:37: error: package javafx.beans.value does not exist
import javafx.beans.value.ChangeListener;
^
Main.java:38: error: package javafx.beans.value does not exist
import javafx.beans.value.ObservableValue;
^
Main.java:39: error: package javafx.collections does not exist
import javafx.collections.FXCollections;
^
Main.java:40: error: package javafx.event does not exist
import javafx.event.Event;
^
Main.java:41: error: package javafx.print does not exist
import javafx.print.PrinterJob;
^
Main.java:42: error: package javafx.scene does not exist
import javafx.scene.AccessibleRole;
^
Main.java:43: error: package javafx.scene does not exist
import javafx.scene.Node;
^
Main.java:44: error: package javafx.scene does not exist
import javafx.scene.Scene;

Aber ich habe das JavaFX verzeichnis obwohl es im Youtube-Video nicht so gemacht wird in den Pfad der Systemvariablen:
C:\Projekte\Java\JTeditorFX\src>path
PATH=.... C:\Program Files\Java\javafx-sdk-11.0.2; .... C:\Program Files\Java\jdk-12.0.2;C:\Program Files\Java\jdk-12.0.2\bin;

Projekte ohne JavaFX lassen sich im Dosfenster compilieren und starten.
 
Zuletzt bearbeitet von einem Moderator:
Woher soll der Compiler auch wissen, dass Du die JavaFX-Module verwenden willst, wenn Du nur javac Main.java schreibst?

weil ich das Javafx-sdk in den Pfad mit aufgenommen habe:
C:\Projekte\Java\JTeditorFX\src>path
PATH=.... C:\Program Files\Java\javafx-sdk-11.0.2; .... C:\Program Files\Java\jdk-12.0.2;C:\Program Files\Java\jdk-12.0.2\bin;

Um es nochmal deutlich auf den Punkt zu bringen:
Projekte ohne JavaFX kann ich compilieren und starten.
Projekte mit JavaFX nicht!
 
Um es nochmal deutlich auf den Punkt zu bringen:
Projekte ohne JavaFX kann ich compilieren und starten.
Projekte mit JavaFX nicht!
Um es nochmal deutlich auf den Punkt zu bringen: der Compiler findet Deine Module nicht, wenn Du ihm nicht sagst, wo sie liegen. Deine PATH-Variable wird von Windows benutzt, um ausführbare Dateien zu finden, nicht aber vom Compiler, um sich irgendwelche Bibliotheken zusammenzusuchen. 🙂

Java:
javac --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml Main.java
könnte funktionieren.
 
In Ordnung, habe verstanden.
Leider hat es nicht geklappt:
C:\Projekte\Java\JTeditorFX\src>javac --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml Main.java
Main.java:130: error: cannot find symbol
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
^
symbol: class Logger
location: class Main
Main.java:570: error: cannot find symbol
private void loadFile(File fileName, Stage stage, TextArea editorArea) {

Frage:
Kann es sein, dass ich jetzt alle import-Anweisungen umbauen muss, weil ich openjdk und openjfx nutze?
 
Habe das hier versucht:
C:\Projekte\Java\JTeditorFX\src>javac --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,java.logging Main.java

Ergebnis:
C:\Projekte\Java\JTeditorFX\src>javac --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,java.logging Main.java
Main.java:130: error: cannot find symbol
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
^
symbol: class Logger
location: class Main
Main.java:570: error: cannot find symbol
private void loadFile(File fileName, Stage stage, TextArea editorArea) {
^
symbol: class File
location: class Main
Main.java:130: error: cannot find symbol
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());

Ein Vorschlag: parallel Netbeans 8.2 i.V. mit einem JDK verwenden, welches JavaFX (2) dabei hatte (z.B. JDK 8-10) oder Apache NetBeans 11.1 i.V. mit OpenJFX ( https://blogs.apache.org/netbeans/entry/what-to-do-with-javafx )

Habe mit Netbeans null Erfahrung.
IntelliJ IDEA kann ich als Alternative zu eclipse.
 
Dann würde ich vermuten, dass Du den Logger nicht importierst. Du kannst Deinen Code hier mal posten, dann aber bitte zwischen Code-Tags [code=Java]Dein Code[/code].
Die Main-Class hat 712 Zeilen, wirklich?

Aber gut, bis zur Main-Methode:
Java:
import javafx.application.Application;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.Event;
import javafx.print.PrinterJob;
import javafx.scene.AccessibleRole;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;

...
public class Main extends Application {

    private static final Logger LOGGER = Logger.getLogger(Main.class.getName());

    private static final String CSS_CONTROLS_ACTIVE = "BedienelementAktiv";
    private static final String CSS_CONTROLS_INACTIVE = "BedienelementNichtAktiv";
    private static final String CSS_CONTROLS_NON_TEXTFIELD_INACTIVE = "BedienelementNichtTextfieldNichtAktiv";
    private static final String CSS_COMBOBOX_ACTIVE_HIGH_CONTRAST = "CBBarrierefreiAktivHoherKontrast";
    private static final String CSS_PART_HIGH_CONTRAST = "HoherKontrast";
    private static final String CSS_TEXT_AREA_INACTIVE = "TextareaNichtAktiv";
    private static final String CSS_TEXTAREA_ACTIVE = "TextareaAktiv";
    private static Boolean isHighContrast;

    private static String startUpPath = "";

    private static int vSuchpos = 0; // TODO this should be remodeled into a property if possible
    /**
     * these two properties act as a "model" for the whole application
     */
    private BooleanProperty isAccessible;
    private StringProperty pathToFile;

    public static void main(String[] arguments) {
    if (arguments.length == 1) {
        startUpPath = arguments[0];
    }
    // Barrierefreiheit: Abfrage ob im Betriebsystem Windows hoher Kontrast
    // aktiviert ist, wenn ja wird er übernommen
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    isHighContrast = (Boolean) toolkit.getDesktopProperty("win.highContrast.on");
    if (isHighContrast) {
        System.setProperty("com.sun.javafx.highContrastTheme", "whiteOnBlack");
    }
    launch();
    }
 
Hier die komplette Fehlerliste:
Main.java:571: error: cannot find symbol
private void loadFile(File fileName, Stage stage, TextArea editorArea) {
^
symbol: class File
location: class Main
Main.java:157: error: cannot find symbol
Toolkit toolkit = Toolkit.getDefaultToolkit();
^
symbol: class Toolkit
location: class Main
Main.java:157: error: cannot find symbol
Toolkit toolkit = Toolkit.getDefaultToolkit();
^
symbol: variable Toolkit
location: class Main
Main.java:166: error: cannot find symbol
URI uri;
^
symbol: class URI
location: class Main
Main.java:167: error: cannot find symbol
Desktop desktop = Desktop.getDesktop();
^
symbol: class Desktop
location: class Main
Main.java:167: error: cannot find symbol
Desktop desktop = Desktop.getDesktop();
^
symbol: variable Desktop
location: class Main
Main.java:168: error: cannot find symbol
File helpFile = new File(System.getProperty("user.dir"), "Hilfe.html");
^
symbol: class File
location: class Main
Main.java:168: error: cannot find symbol
File helpFile = new File(System.getProperty("user.dir"), "Hilfe.html");
^
symbol: class File
location: class Main
Main.java:174: error: cannot find symbol
LOGGER.log(Level.SEVERE, e.getMessage(), e);
^
symbol: variable Level
location: class Main
Main.java:204: error: cannot find symbol
loadFile(new File(pathToFile.getValue()), stage, editorArea);
^
symbol: class File
location: class Main
Main.java:230: error: cannot find symbol
windowTitle.setValue(Paths.get(stringProperty.getValue()).getFileName().toString());
^
symbol: variable Paths
location: class Main
Main.java:431: error: cannot find symbol
.observableArrayList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()));
^
symbol: variable GraphicsEnvironment
location: class Main
Main.java:513: error: cannot find symbol
try (FileWriter vDateispeichern = new FileWriter(pathToFile.getValue())😉 {
^
symbol: class FileWriter
location: class Main
Main.java:513: error: cannot find symbol
try (FileWriter vDateispeichern = new FileWriter(pathToFile.getValue())😉 {
^
symbol: class FileWriter
location: class Main
Main.java:520: error: cannot find symbol
} catch (IOException e) {
^
symbol: class IOException
location: class Main
Main.java:521: error: cannot find symbol
LOGGER.log(Level.SEVERE, "Fehler beim Schreiben der Datei " + pathToFile.getValue(), e);
^
symbol: variable Level
location: class Main
Main.java:547: error: cannot find symbol
File saveFile = vFC.showSaveDialog(stage);
^
symbol: class File
location: class Main
Main.java:563: error: cannot find symbol
File fileName = fileChooser.showOpenDialog(stage);
^
symbol: class File
location: class Main
Main.java:573: error: cannot find symbol
try (BufferedReader in = Files.newBufferedReader(Paths.get(fileName.toString()), StandardCharsets.ISO_8859_1)) {
^
symbol: class BufferedReader
location: class Main
Main.java:573: error: cannot find symbol
try (BufferedReader in = Files.newBufferedReader(Paths.get(fileName.toString()), StandardCharsets.ISO_8859_1)) {
^
symbol: variable StandardCharsets
location: class Main
Main.java:573: error: cannot find symbol
try (BufferedReader in = Files.newBufferedReader(Paths.get(fileName.toString()), StandardCharsets.ISO_8859_1)) {
^
symbol: variable Files
location: class Main
Main.java:573: error: cannot find symbol
try (BufferedReader in = Files.newBufferedReader(Paths.get(fileName.toString()), StandardCharsets.ISO_8859_1)) {
^
symbol: variable Paths
location: class Main
Main.java:577: error: cannot find symbol
} catch (IOException e) {
^
symbol: class IOException
location: class Main
Main.java:578: error: cannot find symbol
LOGGER.log(Level.SEVERE, e.getMessage(), e);
^
symbol: variable Level
location: class Main
24 errors

Vielen Dank für die Hilfe!
 
OK, Du brauchst noch die Imports

Java:
import java.awt.Desktop;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.*;
import java.util.logging.Level;
import java.net.URI;

und das Modul java.desktop (--add-modules). Mal schauen, ob ich was übersehen habe.
 
Du bist ein Gigant!
Das hier:
javac --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,java.logging,java.desktop *.java

Compiliert im Dosfenster unter Windows 10!
Juhu!! Super. Vielen vielen Dank!
 
Gut, jetzt musst Du das nur noch Deiner IDE beibringen 🙂
Ja, in Eclipse klappt es noch nicht.
Habe die Arguments aktualisiert, bekomme aber folgende Fehlermeldung:
Error: Could not find or load main class *.java
Caused by: java.lang.ClassNotFoundException: *.java

achja, bei folgenden Importanweisungen
import java.util.logging.Logger;
import java.awt.Desktop;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.*;
import java.util.logging.Level;
import java.net.URI;

steht in Eclipse auf der linken Seite:
The import ... cannot be resolved

Weiß jemand was ich tun muß?
 
Zuletzt bearbeitet von einem Moderator:
Hi,

ich habe noch eine zweite Klasse:

Java:
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyCombination.ModifierValue;

//Übersetzt Menüshortcuts von englisch ins deutsch
//Lösungsprinzip ist von https://stackoverflow.com/questions/51161764/show-menu-shortcuts-in-german
class GermanModifierMenu extends Menu {

    GermanModifierMenu(String text) {
        super(text);
        setOnShown(e -> hackAcceleratorText());
    }

    private void hackAcceleratorText() {
        getItems().stream()
                .filter(this::needsHack)
                .filter(this::hasStyleableNode)
                .map(this::retrieveAcceleratorTextNode)
                .filter(Label.class::isInstance)
                .map(Label.class::cast)
                .forEach(this::translateCtrl);
    }

    private boolean needsHack(MenuItem item) {
        KeyCombination acc = item.getAccelerator();
        return acc != null && acc.getControl() == ModifierValue.DOWN;
    }

    private boolean hasStyleableNode(MenuItem item) {
        return item.getStyleableNode() != null;
    }

    private Node retrieveAcceleratorTextNode(MenuItem item) {
        return item.getStyleableNode().lookup(".accelerator-text");
    }

    private void translateCtrl(Label label) {
        String translatedLabel = label.getText().replace("Ctrl", "Strg");
        label.setText(translatedLabel);
    }



}

hier bekomme ich folgenden Fehler:
Description Resource Path Location Type
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files GermanModifierMenu.java /JTeditorFX/src line 1 Java Problem

The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

Wißt Ihr was zu tun ist?
 
Wenn ich versuche das Programm im Dosfenster zu starten kommt folgende Fehlermeldung:
java Main --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,java.logging,java.desktop *.java
Fehler: Hauptklasse Main konnte nicht gefunden oder geladen werden
Ursache: java.lang.NoClassDefFoundError: javafx/application/Application
 
Probier mal
Code:
java --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,java.logging,java.desktop -cp . Main
 
Du Held! Funktioniert im Dosfenster! Compilieren und Starten.
Jetzt ist die Frage wie wir das Eclipse beibringen.
 
Hallo,

das Thema JavaFX mit Openjdk und Openjfx ist eine Großbaustelle!
Ich habe jetzt in Eclipse ein neues JavaFX-Projekt erstellt und das compilieren mache ich im Dosfenster mit
javac Main.java --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,java.logging,java.desktop *.java

das Funktioniert!
Wenn ich das compilierte Programm starten möchte mit:
java --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,java.logging,java.desktop -cp . Main

kommt folgende Fehlermeldung:
Fehler: Hauptklasse Main konnte nicht gefunden oder geladen werden
Ursache: java.lang.NoClassDefFoundError: JavaFXUdemy/Main (wrong name: Main)

Warum klappt das compilieren und beim starten gibt es eine Fehlermeldung?
 
Jetzt besorg Dir erstmal eine IDE, die das kann. Auf Dauer über das DOS-Fenster ist ja keine Lösung.

Ansonsten: kann es sein, dass Du in Main.java eine package-Anweisung hast? Dann muss die Klasse auch in einem entsprechenden Verzeichnis befinden.
 
Ich habe Eclipse aktualisiert und e(fx)clipse als Pakete in Eclipse installiert.
Wenn ich nun meinen Texteditor versuche in Eclipse zu compilieren und zu starten bekomme ich in eclipse folgende Fehlermeldung:
The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project

Was muss ich tun?
 

Neue Themen


Zurück
Oben