Jar 文件找不到图像但在 Idea 中找到

问题描述 投票:0回答:1

我正在尝试使用 Jaylib 在 Java 中加载图像,它在 Intellij 中工作但不能作为 Jar。

资源定位方法:

@Nullable
    public String getPath() {
        try {
            String path = Paths.get(ClassLoader.getSystemClassLoader().getResource(this.location).toURI()).toFile().toPath().toString();

            if (new File(path).exists()) {
                return path;
            } else {
                return Paths.get(ClassLoader.getSystemClassLoader().getResource("assets/textures/texture_missing.png").toURI()).toFile().toPath().toString();
            }
        } catch (Exception e) {
            this.LOGGER.error("No object found at location!");
        }

        return null;
    }

我尝试使用

getClass().getResource
getClass().getClassLoader().getResource()
并使用脂肪罐而不是影子罐。

java jar image-loading
1个回答
0
投票

IntelliJ 有不同的方式来决定哪些目录必须是类路径的一部分。很有可能,带有图片的目录在项目设置中被标记为资源目录,但在 pom.xml 中没有标记最后文件根本没有导出到 JAR。

© www.soinside.com 2019 - 2024. All rights reserved.