简体   繁体   中英

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.

This is held in src//main//resources//names.txt. I have an application.yml that references the file location as such

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.

How ever if I copy that JAR to another instance, it complains and says that it cannot find the file referenced

If I browse the JAR the file is there but it is under BOOT-INF/Classes/names.txt

How do I solve this so I can deploy the JAR wherever I want?

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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