Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

java - Javafx app runs perfectly in IDE but when building with maven does not work

I have created two imageviews one from fxml and another from primaryController method

Running from IDE.........1

But when building with maven and running....2

The stacktrace says.....

java.io.FileNotFoundException: srcmain
esourcesorgopenjfxiconsicons8-boombox-48.png (The system cannot find the path specified)
    at java.base/java.io.FileInputStream.open0(Native Method)
    at java.base/java.io.FileInputStream.open(FileInputStream.java:212)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:154)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:109)
    at [email protected]/org.openjfx.PrimaryController.initialize(PrimaryController.java:19)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2655)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2517)
    at [email protected]/org.openjfx.App.start(App.java:16)

                                                      at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    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.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:832)

It cannot find the file specified.

So,I extracted the zip file built by maven and checked that there is not a single image present.So my question is that if there are no images in the zip file then how is the image loaded in case of fxml and not loaded from primaryController method.

Both images are shown from the same file.

package org.openjfx;

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
    try {
        Image image = new Image(new FileInputStream("src/main/resources/org/openjfx/icons/icons8-boombox-48.png"));
        ImageView imageView = new ImageView(image);
        imageView.setFitWidth(100);
        imageView.setFitHeight(100);
        anchorPane.getChildren().add(imageView);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}
question from:https://stackoverflow.com/questions/65645823/javafx-app-runs-perfectly-in-ide-but-when-building-with-maven-does-not-work

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...