Eclipse中使用Gradle構建Java Web項目

來源:互聯網
上載者:User

標籤:build   eclipse   slf4j   depend   apt   1.7   add   bsp   rod   

Gradle是一種自動化建構工具,使用DSL來聲明項目設定。通過Gradle,可以對項目的依賴進行配置,並且自動下載所依賴的檔案,使得構建項目的效率大大提高。

1. 安裝Gradle

下載Gradle的最新版本,並解壓,設定環境變數GRADLE_HOME,並且將%GRADLE_HOME%\bin添加到Path裡面;

2. 安裝Gradle外掛程式

在Eclipse的Help->Eclipse Marketplace中搜尋Gradle,安裝Buildship;

3. 建立Gradle項目

選擇File->New->Other->Gradle->Gradle Project,建立一個Gradle項目:

設定Gradle路徑以及Java路徑:

4. 將Project轉換成Web Project

按右鍵項目,選擇Properties->Project Facets,選擇Dynamic Web Module:

5.  配置Gradle

開啟build.gradle檔案,進行如下編輯:

/* * This build file was auto generated by running the Gradle ‘init‘ task * by ‘simon‘ at ‘16-11-17 涓嬪崍2:49‘ with Gradle 3.2 * * This generated file contains a sample Java project to get you started. * For more details take a look at the Java Quickstart chapter in the Gradle * user guide available at https://docs.gradle.org/3.2/userguide/tutorial_java_projects.html */// Apply the java plugin to add support for Javaapply plugin: ‘java‘// In this section you declare where to find the dependencies of your projectrepositories {    // Use ‘jcenter‘ for resolving your dependencies.    // You can declare any Maven/Ivy/file repository here.    jcenter()}// In this section you declare the dependencies for your production and test codedependencies {    // struts library    compile group: ‘org.apache.struts‘, name: ‘struts2-core‘, version: ‘2.3.24.1‘    compile ‘org.apache.struts:struts2-spring-plugin:2.3.24.1‘    compile ‘org.apache.struts:struts2-json-plugin:2.3.24.1‘     // spring library    compile group: ‘org.springframework‘, name: ‘spring-core‘, version: ‘4.2.3.RELEASE‘    compile group: ‘org.springframework‘, name: ‘spring-web‘, version: ‘4.2.3.RELEASE‘    compile group: ‘org.springframework‘, name: ‘spring-orm‘, version: ‘4.2.3.RELEASE‘    compile group: ‘org.springframework‘, name: ‘spring-aop‘, version: ‘4.2.3.RELEASE‘    compile group: ‘org.springframework‘, name: ‘spring-aspects‘, version: ‘4.2.3.RELEASE‘    compile group: ‘org.springframework‘, name: ‘spring-jdbc‘, version: ‘4.2.3.RELEASE‘         // hibernate library      compile group: ‘org.hibernate‘, name: ‘hibernate-core‘, version: ‘5.0.1.Final‘         // common library    compile ‘org.slf4j:slf4j-api:1.7.13‘    testCompile ‘junit:junit:4.12‘}

倉庫使用了jcenter(),也可以使用mavenCentral(),不過jcenter()更好,包含了mavenCentral()。依賴關係中配置了Struts、Spring、Hibernate的檔案,以及其他一些常用的檔案。

點擊Gradle Executions的Run按鈕,就開始自動下載上述配置的依賴檔案,是不是比以前方便多了?當然,如果已經有了這些檔案,也可以依賴本地的檔案。

Eclipse中使用Gradle構建Java Web項目

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.