Gradle2.0用户指南翻译——第十章. Web 应用程序快速入门

简介: 翻译项目请关注Github上的地址:https://github.com/msdx/gradledoc本文翻译所在分支:https://github.com/msdx/gradledoc/tree/2.0 。
翻译项目请关注Github上的地址:
https://github.com/msdx/gradledoc
本文翻译所在分支:
https://github.com/msdx/gradledoc/tree/2.0 。

第十章. Web 应用程序快速入门

Chapter 10. Web Application Quickstart

本章还在完善中。
This chapter is a work in progress.

本章介绍了Gradle对Web应用程序的相关支持。Gradle提供了两个用于Web应用开发的插件:War和Jetty。 War插件扩展了Java插件,可以用来构建WAR文件。 Jetty插件扩展了War插件,能将Web应用程序部署到嵌入式Jetty Web容器中。 
This chapter introduces some of the Gradle's support for web applications. Gradle provides two plugins for web application development: the War plugin and the Jetty plugin. The War plugin extends the Java plugin to build a WAR file for your project. The Jetty plugin extends the War plugin to allow you to deploy your web application to an embedded Jetty web container.

10.1. 构建一个WAR文件

10.1. Building a WAR file

要构建一个WAR文件,你需要在你的项目当中应用War插件:
To build a WAR file, you apply the War plugin to your project:

示例 10.1. 使用War 插件 - Example 10.1. War plugin

build.gradle

apply plugin: 'war'

注:本示例的代码可以在Gradle的二进制或源代码发行包中的 samples/webApplication/quickstart里找到。
Note: The code for this example can be found at samples/webApplication/quickstart which is in both the binary and source distributions of Gradle.

以上操作也会将Java插件应用到项目中。运行gradle build将对你的项目进行编译,测试和并打成WAR包。 Gradle将查找在src/main/webapp目录中的源文件,并与所编译出来的类文件,及其运行时依赖关系一起包含到WAR文件中。 
This also applies the Java plugin to your project. Running gradle build will compile, test and WAR your project. Gradle will look for the source files to include in the WAR file in src/main/webapp. Your compiled classes, and their runtime dependencies are also included in the WAR file.

Groovy web 应用程序

你可以在单个project中组合多个插件,因此你可以将War和Groovy插件一起使用,构建一个基于Groovy的web应用程序。相应的groovy库也会被加入到WAR文件中。
You can combine multiple plugins in a single project, so you can use the War and Groovy plugins together to build a Groovy based web application. The appropriate groovy libraries will be added to the WAR file for you.

Groovy web applications

10.2. 运行 web 应用程序

10.2. Running your web application

要运行 web 应用程序,需要将 Jetty 插件应用于项目中:
To run your web application, you apply the Jetty plugin to your project:

示例10.2. 使用Jetty插件运行Web应用程序 - Example 10.2. Running web application with Jetty plugin

build.gradle

apply plugin: 'jetty'

以上操作也会将War插件应用到你的项目中。运行gradle jettyRun,将在嵌入式Jetty Web容器中运行你的Web应用程序。运行gradle jettyRunWar将先构建出WAR文件,然后在嵌入式Web容器中运行它。 
This also applies the War plugin to your project. Running gradle jettyRun will run your web application in an embedded Jetty web container. Running gradle jettyRunWar will build the WAR file, and then run it in an embedded web container.

TODO:使用哪个url,配置端口,在适当的位置使用源文件,并且可以编辑你的文件和重新加载。
TODO: which url, configure port, uses source files in place and can edit your files and reload.

10.3. 总结

10.3. Summary

目录
打赏
0
0
0
0
4
分享
相关文章
维护的Web应用程序
【10月更文挑战第4天】维护的Web应用程序
64 4
Django框架适合开发哪种类型的Web应用程序?
Django 框架凭借其强大的功能、稳定性和可扩展性,几乎可以适应各种类型的 Web 应用程序开发需求。无论是简单的网站还是复杂的企业级系统,Django 都能提供可靠的支持,帮助开发者快速构建高质量的应用。同时,其活跃的社区和丰富的资源也为开发者在项目实施过程中提供了有力的保障。
155 62
|
6月前
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
【Azure 应用服务】Web App Service 中的 应用程序配置(Application Setting) 怎么获取key vault中的值
使用 MERN 堆栈构建可扩展 Web 应用程序的最佳实践
使用 MERN 堆栈构建可扩展 Web 应用程序的最佳实践
55 6
使用Dash构建交互式Web应用程序
【10月更文挑战第16天】本文介绍了使用Python的Dash框架构建交互式Web应用程序的方法。Dash结合了Flask、React和Plotly等技术,让开发者能够快速创建功能丰富的数据可视化应用。文章从安装Dash开始,逐步介绍了创建简单应用程序、添加交互元素、部署应用程序以及集成更多功能的步骤,并提供了代码示例。通过本文,读者可以掌握使用Dash构建交互式Web应用程序的基本技巧和高级功能。
125 3
如何使用Vue.js构建响应式Web应用程序
【10月更文挑战第9天】如何使用Vue.js构建响应式Web应用程序
构建响应式Web应用程序:React实战指南
【10月更文挑战第9天】构建响应式Web应用程序:React实战指南
如何使用React和Redux构建现代化Web应用程序
【10月更文挑战第4天】如何使用React和Redux构建现代化Web应用程序
开发复杂Web应用程序
【10月更文挑战第3天】开发复杂Web应用程序
59 2
granian:让你的 Web 应用程序快如闪电
granian:让你的 Web 应用程序快如闪电
131 2

热门文章

最新文章