Gradle: run multiple webapps with Jetty

I want to run two webapps created by the same Gradle project on a Jetty server. Let me call these two webapps “ninja” and “warrior”.

Both web applications are very similar, they differ only in the context application file (see web.xml file) and resources.

For their deployment, these two options are accepted:

  • Use different ports:
http://www.example.com:8080/app (ninja webapp)
http://www.example.com:8081/app (warrior webapp)
  • Use different ways:
http://www.example.com:8080/ninja_app
http://www.example.com:8080/warrior_app

Having one or two instances of Jetty should be in order for this project.

This is my project layout:

/ src / main / java
/ src / main / resources
/ src / main / webapp (ninja webapp)
/ src / main / webapp-warrior

: Gradle?

: Jetty Gradle?

+4
4

, gradle, apply from: Gradle.

webapp, , script , .

gradle, ninja-profile.gradle warrior-profile.gradle, , , :

  • :
  • Jetty: -, .

"" , , :

apply from: "${profile}-profile.gradle"

gradle, -P:

$ gradle -Pprofile=ninja tasks 

$ gradle -Pprofile=warrior tasks
+3

, Gretty gradle : https://github.com/akhikhl/gretty

- . :

  • - "inplace", ..
  • - WAR
  • - WAR
  • WAR maven (, WAR)

:

  • - Jetty Java IDE.
  • - Jetty.
  • Jacoco - , .

, : http://akhikhl.imtqy.com/gretty-doc/

: Gretty.

:)

+7

, , sourceSets, :

  • /src/main/java:
  • /src/main/webapp: webapp .
  • /src/ninjaMain/resources:
  • /src/warriorMain/resources:

build.gradle . webapp, :

apply 'java'
apply 'war'
apply 'cargo'


task createNinjaWar(type: War, dependsOn: classes) {
    baseName = 'ninja'      
    from file('src/main/webapp')
    destinationDir = file("$buildDir/dist")     
    webInf {
        from ('src/ninjaMain/resources') { into 'classes' }
    }
}

task createWarriorWar(type: War, dependsOn: classes) {  
    baseName = 'warrior'    
    from file('src/main/webapp')
    destinationDir = file("$buildDir/dist")                 
    webInf {
        from ('src/warriorMain/resources') { into 'classes' }       
    }
}    

// Deploy
cargo {
    containerId = 'jetty9x'
    port = 8080
    deployable {
        context = 'ninja'           
        file = createNinjaWar.archivePath
    }
    deployable {
        context = 'warrior'
        file = createWarriorWar.archivePath
    }
}

URL- -:

  • http://www.example.com:8080/ninja
  • http://www.example.com:8080/warrior
+1

, . jetty , env build.gradle.

0

Source: https://habr.com/ru/post/1539543/


All Articles