在炼金术 API 错误中找不到符号



尝试在Java中使用AlchemyLanguage API时遇到错误

庞.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>

爪哇类

@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

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

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

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

相关内容

  • 没有找到相关文章

最新更新