星空网 > 软件开发 > Java

Eclipse中使用Gradle构建Java Web项目

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项目:

Eclipse中使用Gradle构建Java Web项目

设置Gradle路径以及Java路径:

Eclipse中使用Gradle构建Java Web项目

4. 将Project转换成Web Project

右键单击项目,选择Properties->Project Facets,选择Dynamic Web Module:

Eclipse中使用Gradle构建Java Web项目

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()。依赖关系中配置了StrutsSpringHibernate的文件,以及其他一些常用的文件。

点击Gradle Executions的Run按钮,就开始自动下载上述配置的依赖文件,是不是比以前方便多了?当然,如果已经有了这些文件,也可以依赖本地的文件。




原标题:Eclipse中使用Gradle构建Java Web项目

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

6月数字外贸新商家数量环比增长45%,浙江中小企业涌入阿里国际站:https://www.ikjzd.com/articles/1679351451060215810
西班牙权威机构发布报告:62%西班牙消费者购物首选AliExpress等平台:https://www.ikjzd.com/articles/1679352468024356865
千亿市场闷声发财:美瞳代工厂冲击上市,新锐品牌海外圈粉百万:https://www.ikjzd.com/articles/1679377731256872961
外贸“新三样”出口暴增,其他行业怎么抄作业?:https://www.ikjzd.com/articles/1679378710199037954
卷到底!卖家打0.1折直逼“0元购”,会员日状况连连!:https://www.ikjzd.com/articles/1679380634402496514
如何在上海找到最适合的FBA头程货代?:https://www.ikjzd.com/articles/1679383202298621954
七月份适合去日本旅游吗 7月份去日本哪里好玩:https://www.vstour.cn/a/363192.html
凤岗汽车站到松山湖风景区 松岗汽车站到凤凰山怎么坐车:https://www.vstour.cn/a/363193.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流