Gradle将项目部署到耳朵

Luc*_*Luc 7 java ear weblogic web-applications gradle

我有以下结构的项目

--MyPrj.ear
  --APP-INF
    --src
    --lib
  --META-INF
    --application.xml
    --weblogic-application.xml
  --WEB_MAIN
    --assets
    --WEB-INF
      --conf
      --web.xml
      --weblogic.xml
Run Code Online (Sandbox Code Playgroud)

我想以下面的结构部署到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
Run Code Online (Sandbox Code Playgroud)

这是我的耳朵配置:

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"
    }
}
Run Code Online (Sandbox Code Playgroud)

我的实际结果:

--MyPrj.ear
  --APP-INF
    --lib
  --com
  --META-INF
    --application.xml
    --weblogic-application.xml
  --WEB_MAIN
    --assets
    --WEB-INF
      --conf
      --web.xml
      --weblogic.xml
Run Code Online (Sandbox Code Playgroud)

无法生成 APP-INF/classes

sol*_*lar 6

要包含.ear文件,您应该build.gradle通过添加apply plugin: 'ear'ear按照本指南中的说明正确填充块来修改.

此外,这里很好地解释了部署过程的神奇之处,不久之后就是wideploy在Gradle中使用工具了.您可能还想查看此处以查找有关此脚本的更多详细信息.


小智 3

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

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

// 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
}
Run Code Online (Sandbox Code Playgroud)