簡體   English   中英

Gradle將項目部署到耳朵

[英]Gradle deploy project to ear

我有以下結構的項目

--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

要包含.ear文件,您應該通過添加apply plugin: 'ear'來修改build.gradle ,並按照本指南中的說明正確填充ear塊。

此外, 這里很好地解釋了部署過程的神奇之處,不久之后就是在Gradle中使用wideploy工具。 您可能還想查看此處以查找有關此腳本的更多詳細信息。

我將從一個觀察開始:構建腳本中的兩個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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM