如何在调试模式下引用资源文件夹? [英] How to refer to resources folder in debug mode?
问题描述
我想用Gradle在Jetty中调试我的web应用程序。我在源代码中有一些属性文件。由于这些文件没有复制到WAR,所以我使用下面的代码来使用 resources
文件夹,
I want to debug my web application in Jetty using gradle. I have some of my property files in source code. Since these files are not copied to WAR, I used the below code to use resources
folder,
sourceSets.main.resources {
srcDirs = ["src/main/java"]; include "**/*.*"
}
这包括WAR中的属性文件。但是当我在eclipse中调试时,它指向 classes
文件夹,它不包含属性文件夹。如何使调试指向资源
文件夹?
This includes properties files in WAR. But when I debug in eclipse, it points to classes
folder which doesnot contain properties folder. How to make debug to point to resources
folder?
Build.gradle:
Build.gradle:
war {
doFirst {
def propertyFile = file "src/main/java/com/properties/about/About.properties"
def props = new Properties()
propertyFile.withReader { props.load(it) }
println "Before setProperty:"
println props.getProperty('releaseDate')
props.setProperty('releaseDate', new Date().format('yyyy-MM-dd-HH:mm:ss'))
propertyFile.withWriter { props.store(it, null) }
println "After setProperty:"
println props.getProperty('releaseDate')
}
buildDir = new File(rootProject.projectDir, "gradleBuild/" + project.name)
}
推荐答案
我解决了这个通过创建 src / main / resources
文件夹并包含所有f除了class文件之外。假设我创建了 properties \sample.properties
并在代码中引用了此路径。现在在调试时以及在部署为WAR时不会出现问题。由具有资源
文件夹中的所有文件都包含在WAR,而不必修改的build.gradle
I solved this by creating src/main/resources
folder and included all files other than class files in it. Say, I created properties\sample.properties
and referred this path in code. Now there occurs no issue while debugging and also when deployed as WAR. By having resources
folder all the files are included in WAR without having to modify build.gradle
这篇关于如何在调试模式下引用资源文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!