【问题标题】:Gradle deploy project to earGradle 将项目部署到耳朵
【发布时间】:2015-08-12 09:45:45
【问题描述】:

我有以下结构的项目

--MyPrj.ear
  --APP-INF
    --src
    --lib
  --META-INF
    --application.xml
    --weblogic-application.xml
  --WEB_MAIN
    --assets
    --WEB-INF
      --conf
      --web.xml
      --weblogic.xml

我想部署到具有以下结构的 PRJ.ear 文件:

--MyPrj.ear
  --APP-INF
    --classes
    --lib
  --META-INF
    --application.xml
    --weblogic-application.xml
  --WEB_MAIN
    --assets
    --WEB-INF
      --conf
      --web.xml
      --weblogic.xml

这是我的耳朵配置:

ear {
    baseName 'PRJ'
    appDirName 'APP-INF/src'
    libDirName 'APP-INF/lib'

    ear{
        into("META-INF"){
            from("META-INF") {
                exclude 'application.xml'
            }
        }
        into("WEB_MAIN") {
            from ("WEB_MAIN")
        }
    }

    deploymentDescriptor {
        webModule 'WEB_MAIN', '/'
        applicationName = "PRJ"
    }
}

我的实际结果:

--MyPrj.ear
  --APP-INF
    --lib
  --com
  --META-INF
    --application.xml
    --weblogic-application.xml
  --WEB_MAIN
    --assets
    --WEB-INF
      --conf
      --web.xml
      --weblogic.xml

无法生成APP-INF/classes

【问题讨论】:

  • 你遇到了什么问题?
  • 我明白了,您已经修改了您的 buid.gradle ,所以问题只是在部署过程中还是您的构建文件有其他问题?

标签: java web-applications gradle weblogic ear


【解决方案1】:

要包含.ear 文件,您应该修改build.gradle,将apply plugin: 'ear' 添加到它并按照this guide 中的说明正确填充ear 块。

另外,here 很好地解释了部署过程的魔力,很快它就是关于在 Gradle 中使用wideploy 工具。 您可能还想查看here 以查找有关此脚本的更多详细信息。

【讨论】:

  • 你能检查一下这个问题吗?stackoverflow.com/questions/31978589/gradle-custom-ear
  • 我要自定义.ear结构
  • 你说你不能部署你的 .ear 是什么意思,有什么特别的错误吗?
  • 没有错误但结果不是我想要的。您可以查看此链接以获取更多详细信息吗? discuss.gradle.org/t/…
  • 疯狂猜测,但你确定你的appDirName 是正确的吗? Ear 任务的默认行为是将应用程序源目录的内容复制到存档的根目录,这(我想)是您的目标,并且由于 APP-INF/classes 在某处丢失,可能 gradle 没有找到正确的方法上课。
【解决方案2】:

我将从一个观察开始:您的构建脚本中的两个ear 实例都指向同一个任务。无需引用ear 两次,即into 声明可以上一级。

首先,将文件夹 APP-INF/src 添加为源集。这将导致编译的类被添加到 EAR 的根目录,因此您必须排除这些。然后你必须告诉ear 任务将编译好的类复制到EAR 中的APP-INF/classes 目录:

// Make sure the source files are compiled.
sourceSets {
    main {
        java {
            srcDir 'APP-INF/src'
        }
    }
}

ear {
    baseName 'PRJ'
    libDirName 'APP-INF/lib'

    into("META-INF") {
        from("META-INF") {
            exclude 'application.xml'
        }
    }
    into("WEB_MAIN") {
        from("WEB_MAIN")
    }

    deploymentDescriptor {
        webModule 'WEB_MAIN', '/'
        applicationName = "PRJ"
    }

    // Exclude the compiled classes from the root of the EAR.
    // Replace "com/javathinker/so/" with your package name.
    eachFile { copyDetails ->
        if (copyDetails.path.startsWith('com/javathinker/so/')) {
            copyDetails.exclude()
        }
    }

    // Copy the compiled classes to the desired directory.
    into('APP-INF/classes') {
        from(compileJava.outputs)
    }

    // Remove empty directories to keep the EAR clean.
    includeEmptyDirs false
}

【讨论】:

  • 太棒了。我会检查它。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多