最近想玩玩gradle,于是在myeclipse中创建了web项目,利用gradle创建,环境为myeclipse2014、windows,gradle2.1.3配置在myeclipse配置gradle插件中进行了说明下步骤如下:
一、创建gradle project
1.选择java Quickstart、finish
2.完后目录结构如下
3.根据web目录特性,在src/main目录下添加webapp文件夹
二、为工程添加web属性
1.project facets中选择Dynamic Web Module
如果java版本过低,调整java版本
2.进行如下设置
将webRoot修改为src\main\webapp目录,并选择创建web.xml
3.设置完成后的目录结构如下
三、设置build.gradle
<span style="font-size:14px;"><span style="font-size:14px;">group 'com.mango.gradle' //在自动生成的基础上添加
version '0.0.1'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war' //在自动生成的基础上添加
sourceCompatibility = 1.5
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'org.springframework:spring-webmvc:4.2.4.RELEASE' //在自动生成的基础上添加
compile 'org.springframework:spring-jdbc:4.2.4.RELEASE'
compile 'org.springframework:spring-aop:4.2.4.RELEASE'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}</span></span>
完成后,点击gradle---------refresh dependencise,依赖包更新完毕
四、编译工程
右击工程Run as----Gradle Build........ 设置build
编译出的东西都在build目录下,包括war包
五、web工程在tomcat中的部署
可采取add deployment的方式,start即可(也可以将build中的war包直接指定在tomcat server.xml中,如下:
<Context path="/mango" privileged="true" reloadable="true" docBase="E:\MyEclipse_Professional_2014\GradleSpringMVCMango\build\libs\GradleSpringMVCMango-1.0.war"></Context>
)
六、打开浏览器输入
<span style="font-size:14px;"><classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry></span>
2. "警告:编码 GBK 的不可映射字符"
options.encoding = "UTF-8"
}