Installing Gradle
- Official website Download gradle binary file http://gradle.org/downloads
- Unzip, and add environment variables
Building a Web project Gradle init
Gradle provides the command to initialize the project, but the command is not yet complete and supports only a few projects http://gradle.org/docs/2.2/userguide/build_init_plugin.html
The project structure is as follows:
- java source directory: Src/main/java
- ava test code directory: src/test/ Java
- Resource file directory: src/main/resources
- Test resource directory: src/test/ Resources
- web project directory: Src/main/webapp equivalent webroot
- can be changed by Webappdirname variable ex:webappdirname=" WebApp "
Under WebApp, create a new Web-inf folder, create a new Web. XML under the Web-inf folder, and the general view file under the WebApp folder. Build.gradle file Create a new Build.gradle file in the SRC sibling directory and add the following code:
apply plugin: ‘java‘
apply plugin: ‘war‘ //用来生成war
apply plugin : ' ECLIPSE-WTP ' //the plug-in used to build the Eclipseweb project (WEB-TOOL-PL Atform)
apply plugin : ' jetty ' //embed jetty server in Project
version = ‘1.0‘ //property
// Uses JDK 7
sourceCompatibility = 1.7
targetCompatibility = 1.7
// 1. Get dependencies from Maven local repository
// 2. Get dependencies from Maven central repository
repositories {
mavenCentral()
}
//Project dependencies
dependencies {
compile ‘ch.qos.logback:logback-classic:1.1.2‘
compile ‘org.springframework:spring-webmvc:4.0.6.RELEASE‘
compile ‘jstl:jstl:1.2‘
//include in compile only, exclude in the war
providedCompile ‘javax.servlet:servlet-api:2.5‘
}
• Open the command line and execute the gradle Eclipse command under the project file path
(usually with Gradle cleaneclipse Eclipse directive: To completely rewrite existing eclipse files, execute a clean task together with its COR Responding Generationtask)
• Open Eclipse,import project come in • Execute Gradle runjetty run project using Tomcat as an embedded server
Https://github.com/bmuschko/gradle-tomcat-plugin
Common commands:
Gradle build compiles the project, builds the build folder, and generates the appropriate jar or war package.
Gradle clean and build instead, delete the build folder
- Gradle tasks to view the task that can be run
- Gradle Eclipse Build development environment, download the defined jar package
- Gradle Cleaneclipse
- Gradle Jettyrun
- Gradle Jettyrunwar would build the WAR file
- Gradle Jettystop
Create a Java Web project using Gradle and Eclipse