实现文件上传进度条的javaweb工程之gradle实战
项目目录结构如下:.
├─scripts
└─src
├─main
│ ├─java
│ │ └─com
│ │ └─hongfei
│ │ ├─entity
│ │ ├─lister
│ │ └─servlet
│ ├─resources
│ └─webapp
│ ├─js
│ ├─META-INF
│ ├─upload
│ └─WEB-INF
└─test
├─java
└─resources
build.gradle文件的内容如下:
运行时必须先执行create_dirs创建src,
apply plugin: "war" apply plugin: "eclipse" apply plugin: "jetty" //清除eclipse输出 task cleanEclipseOutput(type: Delete) { delete eclipse.classpath.defaultOutputDir } //创建src task create_dirs << { sourceSets*.java.srcDirs*.each { it.mkdirs() } sourceSets*.resources.srcDirs*.each { it.mkdirs() } } dependencies { compile "commons-io:commons-io:2.0.1" compile "commons-fileupload:commons-fileupload:1.2.2" providedCompile "javax.servlet:servlet-api:2.5" } //cleanEclipseOutput-task必须放在这句话的前面 jettyRun.dependsOn cleanEclipseOutput repositories { maven { url "http://localhost:8081/nexus/content/groups/public/" } mavenCentral name:'codehaus', artifactUrls: ["http://repository.codehaus.org/"] mavenCentral name:'ibiblio', artifactUrls: ["http://mirrors.ibiblio.org/pub/mirrors/maven2/"] mavenCentral name:'apache', artifactUrls: ["http://people.apache.org/repo/m2-ibiblio-rsync-repository/"] mavenCentral name:'maven', artifactUrls: ["http://repo2.maven.org/maven2/"] mavenCentral name:'lds', artifactUrls: ["https://code.lds.org/nexus/content/repositories/thirdparty/"] mavenCentral name:'m2m', artifactUrls: ["http://repository.m2m.io:8081/nexus/content/groups/public/"] } jettyRun { httpPort = 9080 contextPath = '' classpath = files(eclipse.classpath.defaultOutputDir) + classpath reload = 'manual' }
运行时必须先执行create_dirs创建src;
在依赖(dependencies)中添加j2ee环境支持providedCompile "javax.servlet:servlet-api:2.5"
jettyRun.dependsOn cleanEclipseOutput,是在jetty运行时清空eclipse输出。
jettyRun {
httpPort = 9080
contextPath = ‘‘
classpath = files(eclipse.classpath.defaultOutputDir) + classpath
reload = ‘manual‘
//scanIntervalSeconds = 1
}
设置9080为jetty端口
contextPath为路径
项目辅助bat脚本如下:
build-gradle.bat:
@echo off cd .. gradle create_dirs build eclipse 2>&1 1>log.txt 2>>log.txt 1>>con 2>>con & pause
@echo off cd .. gradle cleanEclipse clean 2>&1 1>log.txt 2>>log.txt 1>>con 2>>con & rmdir /s /q .gradle & pause
@echo off cd .. set GRADLE_OPTS=-Xmx512m -XX:MaxPermSize=512m -Xdebug -Xrunjdwp:transport=dt_socket,address=9000,server=y,suspend=n set GRADLE_USER_HOME=%UserProfile%\.gradle-p2p-pro-app gradle jettyRun 2>&1 1>log.txt 2>>log.txt 1>>con 2>>con & pause
start-gradle.bat(启动eclipse,必须设置setenv.bat):
@echo off call "%~dp0setenv" cd .. start "ECLIPSE" "%ECLIPSE_HOME%\eclipse.exe" -vm "%JAVA_HOME%\bin\javaw.exe"
set JAVA_HOME=E:\tools\jdk1.6 set GRADLE_HOME=E:\tools\gradle-1.9 set ECLIPSE_HOME=E:\tools\eclipse ee\eclipse set PATH=%JAVA_HOME%\bin;%GRADLE_HOME%\bin;%PATH%
http://download.csdn.net/detail/yx511500623/7536827
原文地址:http://blog.csdn.net/bolg_hero/article/details/33416523