首页 文章

将fxml文件包含在可执行jar中

提问于
浏览
1

我'm trying to create a jar file but when i attempt to run it i'得到 java.lang.IllegalStateException: Location is not set.

这是它在我的代码中加载它的方式:

FXMLLoader loader = new FXMLLoader(Main.class.getResource("/view/MainView.fxml"));

jar文件是使用intellij idea构建的:Project Structure - > Artifacts

Solved

我已经设法通过添加来解决它与maven

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

和maven-assembly-plugin

1 回答

  • 2

    通过IDE构建项目不再正确.1305600_t正确无误 . 如果使用Maven构建项目,则应该解决该问题 . 然后将 maven-compiler-plugin 添加到生成的pom.xml中 .

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            ...
        </plugin>
    ...
    </plugins>
    

相关问题