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项目:
设置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 Java apply plugin: 'java' // In this section you declare where to find the dependencies of your project repositories { // 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 code dependencies { // 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按钮,就开始自动下载上述配置的依赖文件,是不是比以前方便多了?当然,如果已经有了这些文件,也可以依赖本地的文件。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
40个Java多线程问题总结
40个问题汇总 1、多线程有什么用? 一个可能在很多人看来很扯淡的一个问题:我会用多线程就好了,还管它有什么用?在我看来,这个回答更扯淡。所谓"知其然知其所以然","会用"只是"知其然","为什么用"才是"知其所以然",只有达到"知其然知其所以然"的程度才可以说是把一个知识点运用自如。OK,下面说说我对这个问题的看法: (1)发挥多核CPU的优势 随着工业的进步,现在的笔记本、台式机乃至商用的应用服务器至少也都是双核的,4核、8核甚至16核的也都不少见,如果是单线程的程序,那么在双核CPU上就浪费了50%,在4核CPU上就浪费了75%。单核CPU上所谓的"多线程"那是假的多线程,同一时间处理器只会处理一段逻辑,只不过线程之间切换得比较快,看着像多个线程"同时"运行罢了。多核CPU上的多线程才是真正的多线程,它能让你的多段逻辑同时工作,多线程,可以真正发挥出多核CPU的优势来,达到充分利用CPU的目的。 (2)防止阻塞 从程序运行效率的角度来看,单核CPU不但不会发挥出多线程的优势,反而会因为在单核CPU上运行多线程导致线程上下文的切换,而降低程序整体的效率。但是单核CPU我们还是要应用...
- 下一篇
Spring Boot基础教程4-配置文件-多环境配置
Spring Boot基础教程1-Spring Tool Suite工具的安装 Spring Boot基础教程2-RESTful API简单项目的快速搭建 Spring Boot基础教程3-配置文件详解:Properties和YAML Spring Boot基础教程4-配置文件-多环境配置 Spring Boot基础教程5-日志配置-logback和log4j2 视频教程:http://www.roncoo.com/course/view/c99516ea604d4053908c1768d6deee3d 源码地址:https://github.com/roncoo/spring-boot-demo 一. 多环境配置的好处: 1.不同环境配置可以配置不同的参数 2.便于部署,提高效率,减少出错 二. Properties多环境配置 1. 配置激活选项 spring.profiles.active=dev 2.添加其他配置文件 三.YAML多环境配置 1.配置激活选项 spring: profiles: active: dev 2.在配置文件添加三个英文状态下的短横线即可区分 ...
相关文章
文章评论
共有0条评论来说两句吧...