TFS Java SDK使用指南

【2018.3.6 更新】

最新版本的TFS Java SDK(14.123.1)支持Java SDK 1.6版本,可以从Oracle的官方网站(http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html)下载。


【2017.5.17 更新】

当在Eclipse中使用Java SDK调试代码的时候,你可能会碰到下面的错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.nativeGetEnvironmentVariable(Ljava/lang/String;)Ljava/lang/String;

你还需要在Java项目的属性设置中指定正确的本地库路径(Native Library Path),如下图:

image

--------------

【2015.12.2 更新】

在这里发布了一篇新的文章“使用Team Explorer Everywhere (TEE) 2015 SDK获取团队项目的签入策略”  http://www.cnblogs.com/danzhang/p/5014547.html


使用微软提供的TFS 2012 SDK for JAVA, 可以方便地在JAVA程序中实现TFS的工作项管理源代码签入签出生成管理等。

下面就从零开始,演示如何使用Eclipse实现JAVA程序调用TFS API,实现TFS的基本的操作。


一、下载必要的软件

    - Eclipse安装程序 http://www.eclipse.org/ 

    - JDK http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html


二、创建Java项目,并导入TFS SDK

image


image


image


在Java项目中创建目录tfssdk,并将SDK中的文件复制到该目录下;将SDK中的文档做成zip文档,并复制到tfssdk目录下(tfs-sdk-11.0-javadoc.zip)

image


打开项目属性

image


添加JAR,并配置库位置和文档位置

image


三、创建并运行样例代码

添加一个样例代码:创建要求工作项

image


package com.mycompany.tfsdemo;

import com.microsoft.tfs.core.TFSTeamProjectCollection;
import com.microsoft.tfs.core.clients.workitem.CoreFieldReferenceNames;
import com.microsoft.tfs.core.clients.workitem.WorkItem;
import com.microsoft.tfs.core.clients.workitem.files.Attachment;
import com.microsoft.tfs.core.clients.workitem.files.Attachment;
import com.microsoft.tfs.core.clients.workitem.project.Project;
import com.microsoft.tfs.core.clients.workitem.wittype.WorkItemType;

public class CreateWorkItem
{
    public static void main(final String[] args)
    {
        //Attachment att1;
        //att1 = new Attachment("","");
       
        TFSTeamProjectCollection tpc = SnippetSettings.connectToTFS();

        Project project = tpc.getWorkItemClient().getProjects().get(SnippetSettings.PROJECT_NAME);

        // Find the work item type matching the specified name.
        WorkItemType RequirementWorkItemType = project.getWorkItemTypes().get("要求");

        // Create a new work item of the specified type.
        WorkItem newWorkItem = project.getWorkItemClient().newWorkItem(RequirementWorkItemType);

        // Set the title on the work item.
        newWorkItem.setTitle("Example Work Item");


        // Add a comment as part of the change
        newWorkItem.getFields().getField(CoreFieldReferenceNames.HISTORY).setValue(
            "<p>Created automatically by a sample</p>");

        // Save the new work item to the server.
       
        //TODO: add attachments while creating new work item
        //newWorkItem.getAttachments().add(att1);
       
        newWorkItem.save();

       
       
        System.out.println("Work item " + newWorkItem.getID() + " successfully created");
    }
}

运行代码,成功

image

http://www.cnblogs.com/danzhang/  ALM MVP 张洪君

posted on 2014-05-11 23:53  danzhang  阅读(4525)  评论(0编辑  收藏  举报

导航