2017-10-15 61 views
1

在連接到tfs時出現以下錯誤。線程「main」中的異常java.lang.UnsatisfiedLinkError:com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.nativeGetEnvironmentVariable

異常線程 「main」 java.lang.UnsatisfiedLinkError中:com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.nativeGetEnvironmentVariable

代碼: 公共類ConnectionToVisualStudio {

public static TFSTeamProjectCollection connectToTFS() 
{ 
    System.setProperty("com.microsoft.tfs.jni.native.base-directory", "C:\\Users\\userName\\native"); 
    TFSTeamProjectCollection tpc = null; 
    Credentials credentials; 

    credentials = new UsernamePasswordCredentials("username","password"); 
    tpc = new TFSTeamProjectCollection(URIUtils.newURI("https://xyz.visualstudio.com/MyFirstProject"), credentials); 
    return tpc; 
} 
public static void main(final String[] args) 
{ 
    TFSTeamProjectCollection tpc; 

    tpc = ConnectionToVisualStudio.connectToTFS(); 
    Project project = tpc.getWorkItemClient().getProjects().get("MyFirstProject"); 
    // Find the work item type matching the specified name. 
    WorkItemType bugWorkItemType = project.getWorkItemTypes().get("Bug"); 

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

    // 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. 
    newWorkItem.save(); 

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

}

回答

1

似乎你沒有正確設置com.microsoft.tfs.jni.native.base-directory作爲系統屬性。

剛剛嘗試如下設置它:

System.setProperty("com.microsoft.tfs.jni.native.base-directory", "C:\Users\userName\native"); 

或將其設置在命令提示符:

java.exe -D"com.microsoft.tfs.jni.native.base-directory=C:\Users\Username\YourApplication\native" 

參考這篇文章:Getting going with the TFS Java API

+0

@gurchet辛格有你在上面解決問題解?任何更新? –

+0

感謝它現在的工作 –

相關問題