Search code examples
javajavafxmaven-2maven-assembly-plugin

Create working .jar out of Maven-Project - JavaFX (Afterburner.fx) Project : Currently stuck with Errormessage


I´ve created a small JavaFx Project with the use of the afterburner.fx framework. It works fine when I start it in the IDE (IntelliJ), but after I created a fat .jar out of it via the "maven-assembly-plugin" it fails to open the Second View.


Pom.xml:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>

            </configuration>
            <executions>
                <execution>
                    <id>assemble-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>com.company.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

SetupPresenter.onStart():

public void onStart(){
    InProgressView inProgressScreen = new InProgressView();
    Scene scene = new Scene(inProgressScreen.getView());
    window.setScene(scene);
    window.setTitle("Currently Running");
    window.show();

    SetRating app = new SetRating();
    new Thread(app).start();
}

Errormessage:

Caused by: java.lang.IllegalStateException: Cannot load file InProgress.fxml
    at com.airhacks.afterburner.views.FXMLView.getResourceCamelOrLowerCase(FXMLView.java:221)
    at com.airhacks.afterburner.views.FXMLView.getFXMLName(FXMLView.java:205)
    at com.airhacks.afterburner.views.FXMLView.<init>(FXMLView.java:83)
    at com.airhacks.afterburner.views.FXMLView.<init>(FXMLView.java:72)
    at com.company.gui.inProgress.InProgressView.<init>(InProgressView.java:5)
    at com.company.gui.setup.SetupPresenter.onStart(SetupPresenter.java:41)
    ... 58 more

The same Errormessage you get in the IDE, when you not include the .fxml in the pom.xml as displayed following:

<resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.fxml</include>
                <include>**/*.css</include>
                <include>**/*.properties</include>
                <include>**/*.png</include>
            </includes>
        </resource>

So probably it has something to do with it. But as I said, the First View is loaded and it is initiated in completly the same way as the Second View:

@Override
public void start(Stage stage) {
    window = stage;

    SetupView setupScreen = new SetupView();
    Scene scene = new Scene(setupScreen.getView());
    window.setScene(scene);
    window.setTitle("ScotlandYard");
    window.show();

}

I´ve tried to find the solution by myself today and tried to generate the fat .jar in varoius other ways, but wasnt able to get a running .jar.


Solution

  • I found the Answer

    Solution for me was just to rename the .fxml Files to start Uppercase: As an example I renamed view1.fxml to View1.fxml. I guess it has something to do with the way windows is accesing the files inside an jar/zip.