Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

510
Visualizações
Why isn't my JavaFX application showing a web browser?

I have a modular JavaFX application with the following Java code:

package webbrowser;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import javafx.scene.web.WebEngine;
import javafx.stage.Stage;

public class WebBrowser extends Application {

    @Override
    public void start(Stage stage) {
        WebView browser = new WebView();
        WebEngine webEngine = browser.getEngine();
        webEngine.load("http://www.oracle.com");
        Scene scene = new Scene(browser, 500, 500);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }

}

Here is the module-info.java file:

module webBrowser {
    requires javafx.controls;
    requires javafx.web;
    
    exports webbrowser;
}

I compile the modular JavaFX application with the following command:

javac -d out --module-source-path . --module-path $JAVAFX_SDK/libs:$JAVAFX_JMODS --module webBrowser

I package the modular JavaFX application with the following command:

jpackage --type dmg --module-path $JAVAFX_JMODS:$JAVAFX_SDK/lib:out --add-modules javafx.controls,javafx.web,javafx.graphics,javafx.media --module webBrowser/webbrowser.WebBrowser

Then I save the application in my /Applications folder (I'm on Mac OS) and open the application. The application opens a 500x500 window, but it doesn't render any graphics, and it doesn't open a web browser. The application just opens a white blank 500x500 window.

Why isn't the application running properly?

When I run the application with java (and forego jpackage) the application runs fine in the JVM, opens a web browser, and opens the oracle.com webpage.

java --module-path out:$JAVAFX_JMODS:$JAVAFX_SDK/lib --add-modules javafx.controls,javafx.web --module webBrowser/webbrowser.WebBrowser

Why doesn't the application work when I use jpackage, install the dmg and run the Mac OS app?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The section of the openjfx.io documentation on runtime images, modular from CLI, demonstrates some of the points outlined below and provides examples of the command line arguments to use for compiling, linking, packaging and executing the application.

I suggest you get the linked openjfx demo working in your environment, then try the same for your project.

Some issues to address:

  1. jmods can't be used at runtime, only at compile or link time.

    • e.g. don't pass the jmods to the java command.
    • For more info, see the answer to:
      • Add a custom JMOD to the module path with Java 9
  2. --add-modules is not required for java/javac when you have a module-info.java.

    • for jpackage just list your app module in --add-modules, you don't need to list the javafx package because it can work that out from your module-info.
  3. Your lib directory is inconsistent, always use the same (correct) directory:

    • sometimes you use lib and sometimes you use libs.
  4. Provide an onError handler.

  5. When using jpackage you should have only the JavaFX mods.

    • you don't need the mods and SDK lib, use only mods.

Further points to check are highlighted in the answer to:

  • Java FX Application with Jpackage not work
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda