Gradle:使用Jetty运行多个webapps [英] Gradle: Run multiple webapps with Jetty

查看:156
本文介绍了Gradle:使用Jetty运行多个webapps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将两个由同一个Gradle项目创建的webapps运行到Jetty服务器上。我们称这两个webapp为ninja和warrior。



这两个webapps非常相似,它们只在应用程序上下文文件中有所不同(在web.xml中引用文件)和资源。

为了部署它们,接受这两个选项:


  • 使用不同的端口:



 
http://www.example.com:8080/应用程序(忍者网络应用程序)
http://www.example.com:8081/app(warrior webapp)




  • 使用不同的路径:



 
http://www.example.com:8080 / ninja_app
http://www.example.com:8080/warrior_app

拥有一个或两个Jetty实例应该是

这是我的项目布局:

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

第一个问题:如何用Grad创建两个war文件第二个问题:如何使用Gradle部署Jetty Server中的两个war文件?

解决方案

如果您不想创建两个不同的项目,则可能需要使用Gradle中的apply from:功能创建两个不同的gradle配置文件。



对于每个Web应用程序实例,忍者和战士,您必须创建一个脚本文件,其中包含特定于个人资料的所有信息。



在这些新的gradle构建文件中,ninja-profile.gradle和warrior-profile.gradle,可以设置不同于忍者和战士的特定配置,可以是:


  1. 资源文件夹:您可以为每个实例
    创建一个单独的资源文件夹

  2. Jetty配置:如果您想运行两个
    不同的2个webapps实例,它们中的每一个都位于分离的
    jetty实例中。

在您的main构建文件中,您可以定义所有配置文件和构建需求的常用功能,并添加以下行:

 适用于:$ {profile} -profile.gradle

运行Gradle时,您可以使用-P选项传递概要文件的名称:

  $ gradle  - Pprofile =忍者任务

  $ gradle -Pprofile = warrior任务


I want to run two webapps created by the same Gradle project into a Jetty server. Let's call these two webapps "ninja" and "warrior".

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

In order to deploy them, 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 paths:

http://www.example.com:8080/ninja_app
http://www.example.com:8080/warrior_app

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

This is my project layout:

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

First question: How to create two war files with Gradle?

Second question: How to deploy the two war files in the Jetty Server with Gradle?

解决方案

If you don't want to create two different projects, you may want to create two different gradle profiles, using the apply from: feature from Gradle.

For each webapp instance, ninja and warrior, you must create a script file with all the information specific for the profile.

In these new gradle build files, ninja-profile.gradle and warrior-profile.gradle, you can set the specific configurations that differ from ninja to warrior, which in this case could be:

  1. Resources folder: you can create a separated resources folder for each of the instances
  2. Jetty configuration: if you want to run two different instances of the 2 webapps, each of them in a separated jetty instance.

In your "main" build file you define everything that is common for all profile and build needs, plus you add the following line:

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

When you run Gradle you can pass the name of the profile using the -P option:

$ gradle -Pprofile=ninja tasks 

or

$ gradle -Pprofile=warrior tasks

这篇关于Gradle:使用Jetty运行多个webapps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆