Hibernate-cfg.xml没有添加到war classes文件夹中。我正在使用以下脚本将Web应用程序部署到tomcat。复制后,当我启动tomcat时,gettign在错误以下
eNotFoundException:类路径资源[hibernate.cfg.xml]无法解析URL,因为它不存在
应用插件:“java”
套用外挂程式:'war'
sourceCompatibility = 1.7
应用插件:“eclipse”
储存库{
mavenCentral()
}
依赖项{
compile("javax.servlet:jstl:1.2")
compile("org.springframework:spring-context:4.0.3.RELEASE")
compile("org.springframework:spring-webmvc:4.0.3.RELEASE")
compile("org.springframework:spring-web:4.0.3.RELEASE")
compile("org.springframework:spring-aop:4.0.3.RELEASE")
compile("org.springframework:spring-aspects:4.0.3.RELEASE")
compile("org.springframework:spring-beans:4.0.3.RELEASE")
compile("org.springframework:spring-core:4.0.3.RELEASE")
compile("org.springframework:spring-expression:4.0.3.RELEASE")
compile("org.springframework:spring-jdbc:4.0.3.RELEASE")
compile("org.springframework:spring-orm:4.0.3.RELEASE")
compile("org.eclipse.persistence:javax.persistence:2.0.0")
compile("antlr:antlr:2.7.7")
compile("commons-logging:commons-logging:1.1.1")
compile("org.hibernate:hibernate-commons-annotations:3.2.0.Final")
compile("org.hibernate:hibernate-core:4.3.5.Final")
compile("org.apache.derby:derbyclient:10.12.1.1")
compile("javax.validation:validation-api:1.0.0.GA")
compile("org.slf4j:slf4j-api:1.7.5")
}
task deploy (dependsOn: war){
copy {
from "build/libs"
into "C:/soft/apache-tomcat-7.0.67/webapps"
include "*.war"
}
}
/*task startTomcat(dependsOn:deploy,type:Exec) {
workingDir "C:/mdi/soft/apache-tomcat-7.0.67/bin"
commandLine 'cmd', '/c', 'startup.bat'
}*/
task startTomcat << {
def processBuilder = new ProcessBuilder(['cmd','/c','startup.bat'])
processBuilder.directory(new File("C:/soft/apache-tomcat-7.0.67/bin"))
processBuilder.start()
}
// Set source directory
// War file name
war
{
war.baseName = 'userregisteration'
project.webAppDirName = 'WebContent'
sourceSets{
main {
java {
srcDir 'src'
}
}
}
}
最佳答案
在您的 war 任务中添加一个from闭包:
from(<directory containing Hibernate-cfg.xml>){
into <'directory in the war in which you'd like the file to be placed'>
include 'Hibernate-cfg.xml'
}
这也是很基本的。我建议也许再次阅读Gradle手册以获得对使用文件的更好的了解。
关于gradle - Gradle War命令不包括休眠CFG文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35132645/