首页 > 解决方案 > Intellij Idea 构建的 jar 不包含 /src 目录

问题描述

我已经用 Intellij IDEA 构建了我的 jar 文件。在我的代码中的某处,我的 fxml 文件有这个静态动态文件路径:

private static URL fxmlResourcePath2 =
        new URL("file://" + System.getProperty("user.dir")
                + File.separator
                + "src"
                + File.separator
                + "dev"
                + File.separator
                + "folling"
                + File.separator
                + "resources"
                + File.separator
                + "fxml"
                + File.separator
        )

注意我还尝试了许多其他版本,例如

    private static URL fxmlResourcePath =
        new URL("file://" + new File(
                "src${File.separator}"+
                "dev${File.separator}" +
                "folling${File.separator}" +
                "resources${File.separator}" +
                "fxml${File.separator}").absolutePath + File.separator
        )

现在,这与我当前的项目结构完美配合 虽然一旦我构建了 jar,/src目录就会消失,jar tf thejarofsubject.jar > output.txt 在快速搜索“src”后没有任何结果。解压 jar 会发现它立即从/dev目录开始。我不能只从我的动态路径中删除“src”,否则它不会在我的 IDE 中运行,但我也不能只保留它,因为在这种情况下它不能在 IDE 之外工作。我究竟做错了什么?

标签: javaintellij-ideafilepath

解决方案


推荐阅读