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

cannot find symbol in alchemy api error

我在 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 class

@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

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

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

确保您的 pom 正在提取所有依赖项,因为看起来 java-sdk 不在 class 路径中,即使它在 pom.xml[=12= 中]