none
已解决*JAVA TFS API 发起连接 返回错误UnsatisfiedLinkError:NativePlatformMisc.nativeGetEnvironmentVariable RRS feed

  • 问题

  • 参照着TFS自带的com.microsoft.tfs.sdk.samples.snippets中的SnippetsSamplesConnectionAdvisor.java和SnippetSettings.java。

    主要代码如下:

    public static String USERNAME = "Administrator";
    public static String PASSWORD = "123";
    public static String SERVER_URL = "http://10.204.83.63:8080/tfs";
    public static String COLLECTION_URL = "http://10.204.83.63:8080/tfs/DefaultCollection";
    public static String HTTP_PROXY_URL = null;
    public static String HTTP_PROXY_USERNAME = "";
    public static String HTTP_PROXY_PASSWORD = "";
    
    public static TFSTeamProjectCollection connectToTFS()
        {
            TFSTeamProjectCollection tpc = null;
            Credentials credentials;
            if ((USERNAME == null || USERNAME.length() == 0) && CredentialsUtils.supportsDefaultCredentials())
            {
                credentials = new DefaultNTCredentials();
            }
            else
            {
                credentials = new UsernamePasswordCredentials(USERNAME, PASSWORD);
            }
    
            URI httpProxyURI = null;
    
            if (HTTP_PROXY_URL != null && HTTP_PROXY_URL.length() > 0)
            {
                try
                {
                    httpProxyURI = new URI(HTTP_PROXY_URL);
                }
                catch (URISyntaxException e)
                {
                    // Do Nothing
                }
            }
    //SnippetsSamplesConnectionAdvisor来自于com\microsoft\tfs\sdk\samples\snippets\com\microsoft\tfs\sdk\samples\snippets\SnippetsSamplesConnectionAdvisor.java
            SnippetsSamplesConnectionAdvisor connectionAdvisor = new SnippetsSamplesConnectionAdvisor(httpProxyURI);
    
            tpc = new TFSTeamProjectCollection(URIUtils.newURI(COLLECTION_URL), credentials, connectionAdvisor);
    
            tpc.ensureAuthenticated();
        }

    执行到tpc.ensureAuthenticated();即报错如下

    STACKTRACE :

    Exception in thread "main" java.lang.UnsatisfiedLinkError: com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.nativeGetEnvironmentVariable(Ljava/lang/String;)Ljava/lang/String;
    at com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.nativeGetEnvironmentVariable(Native Method)
    at com.microsoft.tfs.jni.internal.platformmisc.NativePlatformMisc.getEnvironmentVariable(NativePlatformMisc.java:134)
    at com.microsoft.tfs.jni.PlatformMiscUtils.getEnvironmentVariable(PlatformMiscUtils.java:52)
    at com.microsoft.tfs.core.config.httpclient.DefaultHTTPClientFactory.shouldAcceptUntrustedCertificates(DefaultHTTPClientFactory.java:288)
    at com.microsoft.tfs.core.config.httpclient.DefaultHTTPClientFactory.configureClientParams(DefaultHTTPClientFactory.java:324)
    at com.microsoft.tfs.core.config.httpclient.DefaultHTTPClientFactory.newHTTPClient(DefaultHTTPClientFactory.java:137)
    at com.microsoft.tfs.core.TFSConnection.getHTTPClient(TFSConnection.java:1041)
    at com.microsoft.tfs.core.TFSConnection.getWebService(TFSConnection.java:874)
    at com.microsoft.tfs.core.config.client.DefaultClientFactory$9.newClient(DefaultClientFactory.java:271)
    at com.microsoft.tfs.core.config.client.DefaultClientFactory.newClient(DefaultClientFactory.java:91)
    at com.microsoft.tfs.core.TFSConnection.getClient(TFSConnection.java:1470)
    at com.microsoft.tfs.core.TFSTeamProjectCollection.getWorkItemClient(TFSTeamProjectCollection.java:370)
    at MethodBox.main(MethodBox.java:37)


    TFS C#开发不动人员 这个职业不广泛



    2015年12月1日 8:38

答案

全部回复