VSCode support for OpenJFX

87 views Asked by At

I have made an OpenJFX project and am running it with the following options:

--module-path ${JAVAFX_HOME} --add-modules=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web

This works as expected and creates the application upon running. The problem is with VSCode linting. It says that "package javafx.application does not exist" amongst other packages. Is there a way to point VSCode to the packages or something along those lines. How can I get intellisense to work with OpenJFX.

I am running on Ubuntu 22.04.3 with java version openjdk 20.0.1.

I have tried changing the classpath in VSCode and adding the jars to the referenced libraries.

Edit:
Added sources to settings.json as recommended by @JialeDu

{
    "java.project.referencedLibraries": {
        "include": [
            "/usr/share/openjfx/lib/*.jar"
        ],
        "sources": {
            "/usr/share/openjfx/lib/javafx-swt.jar": "/usr/share/openjfx/lib/src.zip",
            "/usr/share/openjfx/lib/javafx.web.jar": "/usr/share/openjfx/lib/src.zip",
            "/usr/share/openjfx/lib/javafx.swing.jar": "/usr/share/openjfx/lib/src.zip",
            "/usr/share/openjfx/lib/javafx.media.jar": "/usr/share/openjfx/lib/src.zip",
            "/usr/share/openjfx/lib/javafx.graphics.jar": "/usr/share/openjfx/lib/src.zip",
            "/usr/share/openjfx/lib/javafx.fxml.jar": "/usr/share/openjfx/lib/src.zip",
            "/usr/share/openjfx/lib/javafx.controls.jar": "/usr/share/openjfx/lib/src.zip",
            "/usr/share/openjfx/lib/javafx.base.jar": "/usr/share/openjfx/lib/src.zip"
        }    
    }
}

I still have red lines under half of my code, even tough it runs properly enter image description here

0

There are 0 answers