2017-09-25 123 views
0

我想使用谷歌云云自然語言的API。谷歌云云自然語言API

我已經有了谷歌雲中運行的帳戶。 我支持雲自然語言API服務和生成服務帳戶密鑰和下載到本地。

我火腿使用我使用的Eclipse爲IDE上的Mac

護目鏡默認程序

LanguageServiceClient language = LanguageServiceClient.create(); 

// The text to analyze 
String text = "My stay at this hotel was not so good"; 
Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build(); 

// Detects the sentiment of the text 
Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment(); 

System.out.printf("Text: %s%n", text); 
System.out.printf("Sentiment: %s, %s%n", sentiment.getScore(), sentiment.getMagnitude()); 

當我運行應用程序,我得到了錯誤

java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute E 
ngine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs 
/application-default-credentials for more information. 

我什至增加GOOGLE_APPLICATION_CREDENTIALS在終端出口和使用「printenv」它顯示了這樣的

GOOGLE_APPLICATION_CREDENTIALS=/Users/temp/Downloads/Sentiment-0e556940c1d8.json 

的路徑,但它依然不能與某些命中和試驗方法,我發現在Eclipse中我們可以配置運行工作。

在那裏,我已經添加的環境變量後,當我運行程序,它工作正常。現在

我的問題是我實現J2EE項目中的代碼和EAR文件中Wildfly部署。 我再次收到同樣的錯誤。現在我不知道在蜻蜓或哪裏設置enviromnet變量的位置?

回答

0

最後,我找到了一種方法來設置GOOGLE_APPLICATION_CREDENTIALS作爲環境變量中Wildfly

  1. 如果您是通過Eclipse中通過雙擊運行服務器

    • 打開Wildfly服務器設置一下您的服務器裏面 服務器選項卡
    • 點擊「打開啓動配置」
    • 移動到 「環境」 選項卡並添加新的變量作爲鍵值

    例如

    GOOGLE_APPLICATION_CREDENTIALS /Users/temp/Downloads/Sentiment-0e556940c1d8.json

  2. 如果您正在運行使用終端的服務器

    默認情況下,Wildfly會在獨立內部尋找其他設置.conf文件。

    剛纔打開野蠅/ bin/standalone。CONF文件,並添加以下行

    GOOGLE_APPLICATION_CREDENTIALS = /用戶/溫度/下載/情感0e556940c1d8.json

那它。你很好走.....