【问题标题】:cannot find symbol in alchemy api error在炼金术 api 错误中找不到符号
【发布时间】:2016-06-21 22:54:33
【问题描述】:

尝试在 Java 中使用 AlchemyLanguage API 时出现错误

pom.xml

<dependencies>
  <dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-servlet_3.0_spec</artifactId>
    <version>1.0</version>
  </dependency>
  <dependency>
    <groupId>com.ibm.watson.developer_cloud</groupId>
    <artifactId>java-sdk</artifactId>
    <version>2.8.0</version>
  </dependency>
  <dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
  </dependency>
  <dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-servlet_3.0_spec</artifactId>
    <scope>provided</scope>
  </dependency>
</dependencies>

java类

@WebServlet("/SimpleServlet2")
public class API extends HttpServlet {
  private static final long serialVersionUID = 1L;

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    AlchemyLanguage service = new AlchemyLanguage();
    service.setApiKey("API_KEY_HERE");

    Map<String,Object> params = new HashMap<String, Object>();
    params.put(AlchemyLanguage.TEXT, "IBM Watson won the Jeopardy television show hosted by Alex Trebek");

    DocumentSentiment sentiment = service.getSentiment(params);
    System.out.println(sentiment);
    response.getWriter().print(sentiment.toString());
  }
}

错误日志

[ERROR] src/main/java/wasdev/sample/‌​servlet/API.java:[17,39]
 cannot find symbol symbol: class AlchemyLanguage location: class wasdev.sample.servlet.API
[ERROR] src/main/java/wasdev/sample/‌​servlet/API.java:[22,19]
 cannot find symbol symbol: variable FileUtils location: class wasdev.sample.servlet.API
[ERROR] src/main/java/wasdev/sample/‌​servlet/API.java:[25,9]
 cannot find symbol symbol: variable CredentialUtils location: class wasdev.sample.servlet.API
[ERROR] src/main/java/wasdev/sample/‌​servlet/API.java:[27,22]
 cannot find symbol symbol: variable CredentialUtils

【问题讨论】:

  • [错误] /home/pipeline/0e04c628-e041-41a9-bc51-0e99f59817aa/src/main/java/wasdev/sample/servlet/API.java:[17,14] 找不到符号符号:类 AlchemyLanguage 位置:类 wasdev.sample.servlet.API
  • [错误] /home/pipeline/0e04c628-e041-41a9-bc51-0e99f59817aa/src/main/java/wasdev/sample/servlet/API.java:[17,39] 找不到符号符号:类 AlchemyLanguage 位置:类 wasdev.sample.servlet.API
  • [错误] /home/pipeline/0e04c628-e041-41a9-bc51-0e99f59817aa/src/main/java/wasdev/sample/servlet/API.java:[22,19] 找不到符号符号:变量 FileUtils 位置:类 wasdev.sample.servlet.API [错误] /home/pipeline/0e04c628-e041-41a9-bc51-0e99f59817aa/src/main/java/wasdev/sample/servlet/API.java:[25 ,9] 找不到符号符号:变量 CredentialUtils 位置:类 wasdev.sample.servlet.API [错误] /home/pipeline/0e04c628-e041-41a9-bc51-0e99f59817aa/src/main/java/wasdev/sample/servlet/ API.java:[27,22] 找不到符号符号:变量 CredentialUtils

标签: ibm-watson alchemyapi


【解决方案1】:

我已更新您问题中的代码。似乎您的问题与类路径有关。看看这个示例应用程序,它包含 java-sdk 并公开了一个带有一些端点的 JAX-RS 类。

https://github.com/watson-developer-cloud/retrieve-and-rank-java

确保您的 pom 正在拉取所有依赖项,因为 java-sdk 似乎不在类路径中,即使它在 pom.xml

【讨论】:

    猜你喜欢
    • 2016-09-27
    • 2014-04-21
    • 1970-01-01
    • 2015-01-21
    • 2022-07-19
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    相关资源
    最近更新 更多