45500
[![画像の説明をここに入力](https://i.stack.imgur.com/b82Se.jpg)](https://i.stack.imgur.com/b82Se.jpg)Javaを使ってMicrosoftのAzureでComputer
Vision
APIを利用したいと思っています。eclipseで書いているのですが、一つだけ解決できないエラーがあります。Azureのページに載っているクイックスタートのサンプルコードです。

どなたかご教授願います。  
[![エラー内容](https://i.stack.imgur.com/kvIVB.jpg)](https://i.stack.imgur.com/kvIVB.jpg)

```

    //  - Apache HTTP client (org.apache.httpcomponents:httpclient:4.5.5)
    //  - Apache HTTP core (org.apache.httpcomponents:httpccore:4.4.9)
    //  - JSON library (org.json:json:20180130).
    
    import java.net.URI;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.client.utils.URIBuilder;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClientBuilder;
    import org.apache.http.util.EntityUtils;
    import org.json.JSONObject;
    
    public class Main {
        // **********************************************
        // *** Update or verify the following values. ***
        // **********************************************
    
        // Replace <Subscription Key> with your valid subscription key.
        private static final String subscriptionKey = "******************************";
    
        // You must use the same region in your REST call as you used to get your
        // subscription keys. For example, if you got your subscription keys from
        // westus, replace "westcentralus" in the URI below with "westus".
        //
        // Free trial subscription keys are generated in the westcentralus region. If you
        // use a free trial subscription key, you shouldn't need to change this region.
        private static final String uriBase =
                "https://westcentralus.api.cognitive.microsoft.com/vision/v2.0/analyze";
    
        private static final String imageToAnalyze =
                "https://upload.wikimedia.org/wikipedia/commons/" +
                        "1/12/Broadway_and_Times_Square_by_night.jpg";
    
        public static void main(String[] args) {
            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    
            try {
                URIBuilder builder = new URIBuilder(uriBase);
    
                // Request parameters. All of them are optional.
                builder.setParameter("visualFeatures", "Categories,Description,Color");
                builder.setParameter("language", "en");
    
                // Prepare the URI for the REST API call.
                URI uri = builder.build();
                HttpPost request = new HttpPost(uri);
    
                // Request headers.
                request.setHeader("Content-Type", "application/json");
                request.setHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
    
                // Request body.
                StringEntity requestEntity =
                        new StringEntity("{\"url\":\"" + imageToAnalyze + "\"}");
                request.setEntity(requestEntity);
    
                // Make the REST API call and get the response entity.
                HttpResponse response = httpClient.execute(request);
                HttpEntity entity = response.getEntity();
    
                if (entity != null) {
                    // Format and display the JSON response.
                    String jsonString = EntityUtils.toString(entity);
                    JSONObject json = new JSONObject(jsonString);
                    System.out.println("REST Response:\n");
                    System.out.println(json.toString(2));
                }
            } catch (Exception e) {
                // Display error message.
                System.out.println(e.getMessage());
            }
        }
    }
    
```
CC BY-SA 4.0
2018-07-11T05:07:41.953
45498
2018-07-11T11:03:59.867
2018-07-11T05:53:56.547
29253
29253
question
java eclipse api azure
Java　AzureのAPIを利用したプログラムのエラー
以下のライブラリーをビルドパスに含めていないのでは。

  * Apache HTTP client (org.apache.httpcomponents:httpclient:4.5.5)
  * Apache HTTP core (org.apache.httpcomponents:httpccore:4.4.9)
  * JSON library (org.json:json:20180130).
CC BY-SA 4.0
2018-07-11T05:29:56.787
45500
2018-07-11T05:42:30.750
2018-07-11T05:42:30.750
21092
21092
45498
answer
環境は違いますが、僕の環境では動きました。  
ですが、

> org.apache.httpcomponents:httpclient:4.5.5  
>  org.apache.httpcomponents:httpccore:4.4.9  
>  org.json:json:20180130

の他に  
[commons-logging](https://mvnrepository.com/artifact/commons-logging/commons-
logging/1.1.1)をclass passに含める必要がありました。(僕は1.1.1を使いました)

commons-loggingがない場合は僕の環境では以下のエラーがありました。

> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/commons/logging/LogFactory  
>  at
> org.apache.http.conn.ssl.DefaultHostnameVerifier.(DefaultHostnameVerifier.java:82)  
>  at
> org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955)  
>  at Main.main(Main.java:35)  
>  Caused by: java.lang.ClassNotFoundException:
> org.apache.commons.logging.LogFactory  
>  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)  
>  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)  
>  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)  
>  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)  
>  ... 3 more
CC BY-SA 4.0
2018-07-11T11:03:59.867
45510
2018-07-11T11:03:59.867
24823
45498
answer