简体   繁体   English

Gradle构建后JAR中缺少资源文件

[英]Resource file missing from JAR after gradle build

I have a resource file call names.txt that is called by my code when I hit a rest endpoint. 我有一个资源文件调用names.txt,当我点击一个rest端点时,我的代码会调用它。

This is held in src//main//resources//names.txt. 它保存在src // main // resources // names.txt中。 I have an application.yml that references the file location as such 我有一个application.yml这样引用文件位置

file:
    namesPath: src//main//resources//names.txt

when I build and run my solution everything works fine. 当我构建并运行我的解决方案时,一切正常。 If i run the jar from the commandline outside the IDE it also works fine. 如果我从IDE外部的命令行运行jar,它也可以正常工作。

How ever if I copy that JAR to another instance, it complains and says that it cannot find the file referenced 如果我将该JAR复制到另一个实例,它会抱怨并说找不到所引用的文件

If I browse the JAR the file is there but it is under BOOT-INF/Classes/names.txt 如果我浏览JAR文件,则该文件在那里,但它位于BOOT-INF / Classes / names.txt下

How do I solve this so I can deploy the JAR wherever I want? 我该如何解决这个问题,以便可以在任何需要的地方部署JAR?

It is hard to say what is wrong without seeing your build.gradle file but I would expect if you put something like below in your build file the resource files should end up in the right location: 在看不到build.gradle文件的情况下很难说出什么问题,但是我希望如果在构建文件中放入以下内容,则资源文件应该放在正确的位置:

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', 'src/gen/java']
        }
        resources {
            srcDirs = [src/main/resources']
        }
    }
    ....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM