Gradle:将配置文件添加到类路径
在一个简单的gradle项目中,我在项目根目录下有一个config文件夹,其中有一个config.json。我想把这个文件放在读取它的路径上Gradle:将配置文件添加到类路径,gradle,Gradle,在一个简单的gradle项目中,我在项目根目录下有一个config文件夹,其中有一个config.json。我想把这个文件放在读取它的路径上 def myconfigfile = new File("config", "config.json") def configset = files(myconfigfile) task runExample ( dependsOn: 'classes', type: JavaExec ) { main = 'com.
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下。如果我理解得很好,最好的选择似乎是通过
project.file
方法引用config.json
,有关文档,请参阅
它将是:
project.file("confif${File.separator}config.json")