问题
I'm getting an error when trying to use the AlchemyLanguage API in Java
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 log
[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
回答1:
I've updated the code in your question. Seems like your problem is related to the classpath. Take a look at this sample application which includes the java-sdk and exposes a JAX-RS class with some endpoints.
https://github.com/watson-developer-cloud/retrieve-and-rank-java
Make sure you pom is pulling all the dependencies as it seems like the java-sdk is not in the classpath even that it's in the pom.xml
来源:https://stackoverflow.com/questions/35859856/cannot-find-symbol-in-alchemy-api-error