1

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.

kiwicomb123
  • 1,503
  • 21
  • 26

1 Answers1

0

Okay I tried these things and got it working.

  1. Tested in Junit -> Works
  2. In the full webapp -> Doesn't work (ClassNotFound)
  3. Seperated the RConnection into it's own pure Java program -> works but gives this warning:

"will not be exported or published, Runtime ClassNotfoundExceptions may result" Someone on StackOverflow solved a similar problem here Eclipse warning: XXXXXXXXXXX.jar will not be exported or published. Runtime ClassNotFoundExceptions may result by adding the lib files to the WEB-INF/lib of their project, however, this is not a web app so there is no such folder here. I tried this method in the actual web app with No success

  1. I tried copying the RServe and REngine library jars files into the tomcat libs folder. e.g: /tomcat/lib/ and THIS WORKED.
Community
  • 1
  • 1
kiwicomb123
  • 1,503
  • 21
  • 26