【问题标题】:Gradle war command not including hibernate cfg fileGradle 战争命令不包括休眠 cfg 文件
【发布时间】:2016-02-01 14:09:53
【问题描述】:

Hibernate-cfg.xml 未添加到 war 类文件夹中。我正在使用下面的脚本将 web 应用程序部署到 tomcat。复制后,当我启动 tomcat 时,gettign 以下错误 eNotFoundException:类路径资源 [hibernate.cfg.xml] 无法解析 URL,因为它不存在

应用插件:'java' 应用插件:'战争' 源兼容性 = 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'


                     }

                 }
               }
     }

【问题讨论】:

    标签: gradle


    【解决方案1】:

    在你的战争任务中添加一个 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 手册,以更好地了解如何处理文件。

    【讨论】:

    • 我通过在资源文件夹中创建休眠 cfg 文件找到了解决方案。
    • // 设置源目录war{ project.webAppDirName = 'WebContent' sourceSets{ main { java { srcDir 'src' } resources { srcDir 'resources' } } } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 2014-02-04
    • 1970-01-01
    相关资源
    最近更新 更多