gpt4 book ai didi

gradle - Gradle:将配置文件添加到类路径

转载 作者:行者123 更新时间:2023-12-03 03:23:12 24 4
gpt4 key购买 nike

在一个简单的gradle项目中,我在项目根目录下有一个带有config.json的config文件夹。我想将此文件放在读取它的路径上。

    def myconfigfile = new File("config", "config.json")
def configset = files(myconfigfile)

task runExample ( dependsOn: 'classes', type: JavaExec ) {
main = 'com.example.LoadConfigExample'
classpath = sourceSets.main.runtimeClasspath
classpath.add(configset)
args 'ARG1'
}

在Java文件中,我使用以下文件加载文件:
URL u = LoadConfigExample.class.getResource("config.json");

仅使用相对路径并通过文件系统加载会更好吗?我不想将文件放在src / main / resources下。

最佳答案

如果我很好理解,最好的选择似乎是通过config.json方法引用project.file,有关文档,请参阅here

这将是:

project.file("confif${File.separator}config.json")

关于gradle - Gradle:将配置文件添加到类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28545653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com