Create a Java Web project using Gradle and Eclipse

Source: Internet
Author: User
Tags maven central

Installing Gradle
    1. Official website Download gradle binary file http://gradle.org/downloads
    2. 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‘ //用来生成warapply 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 7sourceCompatibility = 1.7targetCompatibility = 1.7  // 1. Get dependencies from Maven local repository// 2. Get dependencies from Maven central repositoryrepositories {mavenCentral()} //Project dependenciesdependencies {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 warprovidedCompile ‘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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.