I've imported all the necessary library files, and it works fine when I do a unit test using JUnit. But, when I run this code in the webapp, I get a ClassNotFoundException. I've commented out all the code that did not cause the exception to occur. It seems the line "connection = new RConnection()" is causing the problem.
I've also tried importing a different version of the Rserve library files, Rserve-0.6.5, with no success.
[update]
I've already added the Rserve and Rengine jars to the Build path for my project using Eclipses options.
Code:
import org.rosuda.REngine.REXP;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
public class RServerAccessor implements ProductInfoDAO {
private RConnection connection;
public List<Product> getProducts(String path) {
List<Product> list = new ArrayList<Product>();
try {
connection = new RConnection();
//connection.eval("source('~/Desktop/Food/workspace/mcApp2/rScripts/ReceiptReader.R')");
//REXP raw = connection.eval("getProducts(\"" + path + "\")");
//String text = raw.asString();
//System.out.println(text);
// String[] items = text.split("\n");
// for(String item: items){
// list.add(new GroceryProduct(item));
// }
} catch (RserveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
connection.close();
}
return list;
}
}
Exception:
Jan 02, 2017 9:27:09 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Service
java.lang.ClassNotFoundException: org.rosuda.REngine.Rserve.RserveException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at ctrl.Service.init(Service.java:41)
Any help appreciated.