在ant里使用tfs任务
对一个在tfs上的项目进行自动编译
使用teamprise的ant插件,详见
http://labs.teamprise.com/build/ant.html
- 安装teamprise的ant插件
下载teamprise-ant-1.2.zip
解压,把teamprise-ant-1.2.jar拷贝到ant的lib目录,完成
- 编写build.xml
<project name="test-teamprise-ant-tasks" basedir="e:/stsworkspace/code" default="deploy"> <property name="ant.lib.dir" value="e:/program/ant-1.8.2/lib"/> <property name="tfs.server" value="http://tfsserver:8080/tfs" /> <property name="tfs_workspace_name" value="GMARTINCN"/> <property name="tfs_project_name" value="$/PROJECT/CODE"/> <typedef resource="com/teamprise/ant/antlib.xml" classpath="${ant.lib.dir}/teamprise-ant-1.2.jar" /> <!-- 检查ant插件是否安装正确 --> <target name="diagnostics"> <tfstasksdiagnostics /> </target> <target name="get" description="get the codes"> <echo message="Get latest source code from tfs..."/> <!-- tfsget命令 指定本地路径 会从关联的服务器取代码 --> <tfsget localpath="${basedir}/src" force="false" /> <tfsget localpath="${basedir}/WebRoot" force="false" /> </target> <!-- 执行工程里的ant文件,完成编译布署 --> <target name="deploy" depends="get" description=" get the codes,compile,package and deploy the output file"> <ant antfile="qk.xml" dir="${basedir}" inheritall="false" inheritrefs="false" target="war" /> </target> </project>
tfs系统任务包括
Task | Description |
---|---|
tfs | Run a generic tfs command |
tfsadd | Add files or folders to a workspace |
tfscheckin | Check in pending changes |
tfscheckout | Check out files and folders so they can be edited |
tfsdelete | Delete files or folders from a workspace |
tfsget | Get files and folders from the server |
tfshistory | Obtain history information on a file or folder |
tfslabel | Manage labels |
tfsparsehistory | Parse the output from tfshistory |
tfstasksdiagnostics | Print out diagnostic information and tests that the Teamprise TFS Ant tasks are correctly installed |
tfsworkfold | Manage working folder mappings for a workspace |
tfsworkspace | Manage workspaces on a TFS server |
使用手册详见
http://download.teamprise.com/cs/3.3.1.11648R/docs/ant/manual.html
- Javac 编译报非法字符 /65279
原因:用UE或记事本编辑过的UTF-8的文件头会加入BOM标识,该标识由3个char组成。在UTF-8的标准里该BOM标识是可有可无的,Sun 的javac 在编译带有BOM的UTF-8的格式的文件时会出现“非法字符:/65279”的错误,但是用Eclipse进行编译却没有问题,原因在于Eclipse使用的是自己的JDT,而非javac
可使用eclipse的jdt编译器
步骤:
1.提取eclipse插件目录plugin中jdt的jar包,包名org.eclipse.jdt.core_3.x.x.v_....jar
eclipse3.7.2里的包是org.eclipse.jdt.core_3.7.2.v_B78_R37x.jar
解压jar包,提取里面的jdtCompilerAdapter.jar
2.把org.eclipse.jdt.core_3.7.2.v_B78_R37x.jar和jdtCompilerAdapter.jar拷到ant的lib目录
3.指定javac任务的compiler属性
<javac source="1.5" target="1.5" destdir="${bin.dir}" nowarn="on" includeAntRuntime="false" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"> <src path="${src.dir}"/> <classpath refid="appClassPath"/> <compilerarg line="-encoding GBK "/> </javac>
ps:由于公司网络问题,如果使用ip地址,跨网段使用,取代码过一会会连接出错,换用服务器机器名,能正常获取代码,可能和防火墙有关。同网段没问题