Gradle构建SSM项目

代码结构:


一、安装gradle插件

1、Eclipse在线安装

Eclipse:help-EclipseMarketplace-搜索框输入BuildShip或者gradle,然后点击Installed,便可下载,接着点击同意,安装好后重启即可。

2、离线安装

Gradle下载地址:http://services.gradle.org/distributions/,选择版本,下载解压到相应目录,然后打开Eclipse中window-preferences设置Gradle路径:

设置好路径后,添加插件,help-Install New Software,然后点击Add,输入:

buildship

http://download.eclipse.org/buildship/updates/e47/releases/2.x

选中,下一步,接着点击同意,等待安装,弹出提示框重启Eclipse。

最后设置环境变量:

环境变量设置好后,测试是否安装成功,cmd输入:gradle -v

安装成功!

二、构建SSM(Spring+SpringMVC+Mybatis)

1、对Web添加Gradle支持,右击项目-Configure-Add Gradle Nature

2、Java Resources中新建resources,用于放配置文件

3、Web项目根目录下新建build.gradle,用于构建依赖

apply plugin: 'java'
apply plugin: 'war' //用来生成war
apply plugin: 'eclipse-wtp' //用来生成Eclipseweb项目的插件(web-tool-platform)
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()
maven{ url"http://maven.aliyun.com/nexus/content/groups/public"}   
}
//Project dependencies 
dependencies {
 compile 'org.apache.tomcat:tomcat-servlet-api:8.0.24'
 compile 'jstl:jstl:1.2'
 compile 'org.springframework:spring-beans:4.3.5.RELEASE'
 compile 'org.springframework:spring-context:4.3.5.RELEASE'
 compile 'org.springframework:spring-context-support:4.3.5.RELEASE'
 compile 'org.springframework:spring-web:4.3.5.RELEASE'
 compile 'org.springframework:spring-webmvc:4.3.5.RELEASE'
 compile 'org.springframework:spring-tx:4.3.5.RELEASE'
 compile 'com.alibaba:druid:1.0.15'
 compile 'org.aspectj:aspectjweaver:1.8.6'
 compile 'mysql:mysql-connector-java:5.1.36'
 compile 'org.mybatis:mybatis-spring:1.3.1'
 compile 'org.mybatis:mybatis:3.4.1'
 compile 'org.springframework:spring-jdbc:4.3.5.RELEASE'
 compile 'junit:junit:4.12'
 compile 'org.springframework:spring-test:4.0.5.RELEASE'
 compile 'com.alibaba:fastjson:1.2.31'
 compile 'log4j:log4j:1.2.17'
 compile group: 'org.freemarker', name: 'freemarker', version: '2.3.25-incubating'
 compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1'
 compile group: 'commons-io', name: 'commons-io', version: '2.2'
 compile group: 'commons-logging', name: 'commons-logging', version: '1.2'
 //compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'
 //compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
//include in compile only, exclude in the war
providedCompile 'javax.servlet:servlet-api:3.0.1'
providedCompile 'javax.servlet.jsp:jsp-api:2.2.1-b03'
}

4、下载依赖包,右击项目-Gradle-Refresh Gradle Project,等待依赖包下载完成

5、把src和resources 添加到build path,Default output folder设置成“项目名称/WebContent/WEB-INF/classes”,这里我的是“Exam/webapp/WEB-INF/classes”。

Java Build Path:

Deployment and Assembly

到此,Gradle构建SSM项目成功!

注:该博客参考一位专业老师的编写的,地址https://blog.csdn.net/write6/article/details/79193821

猜你喜欢

转载自blog.csdn.net/Wuli9468/article/details/80552074