拜托,我需要你的帮助。
我有这个java类
package com.stephen.crawler;
import org.rosuda.JRI.Rengine;
public class JRI_Interface {
Rengine r;
String str_globalPath="/home/pavel/workspace/opendata/r_script/";
public JRI_Interface (String str_fuente) {
r = new Rengine(new String[] { "--no-save" }, false, null);
r.eval("source(\""+str_globalPath+str_fuente+"\")");
}
public void exec_RProcedure(String str_procedure) {
r.eval(str_procedure);
}
public String[] exec_RFunction (String str_procedure) {
return r.eval(str_procedure).asStringArray();
}
}
如果执行:
,它的效果非常好package com.stephen.crawler;
public class JRI_Start_1 {
public static void main(String[] args)
{
JRI_Interface j = new JRI_Interface("staticdata.r");
j.exec_RProcedure("loadParametersOD()");
String obj[]=j.exec_RFunction("getLoadedParametersOD()");
System.out.println (obj.length);
}
}
但是,当我使用带有Tomcat的jsp执行时:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
%>
<%@ page import="com.stephen.crawler.*" %>
<%@ page import="org.rosuda.JRI.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My Title</title>
</head>
<%
JRI_Interface j = new JRI_Interface("staticdata.r");
j.exec_RProcedure("loadParametersOD()");
String obj[]=j.exec_RFunction("getLoadedParametersOD()");
%>
<body>
</body>
</html>
我收到以下消息:
> org.apache.jasper.JasperException: Ha sucedido una excepción al
> procesar la página JSP /Inicio.jsp en línea 14
>
> 11: <title>My Title</title>
> 12: </head>
> 13: <%
> 14: JRI_Interface j = new JRI_Interface("staticdata.r");
> 15: j.exec_RProcedure("loadParametersOD()");
> 16: String obj[]=j.exec_RFunction("getLoadedParametersOD()");
> 17: %>
>
> Stacktrace:
> org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> causa raíz
>
> javax.servlet.ServletException: java.lang.NoClassDefFoundError:
> org/rosuda/JRI/Rengine
> org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
> org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
> org.apache.jsp.Inicio_jsp._jspService(Inicio_jsp.java:146)
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> causa raíz
>
> java.lang.NoClassDefFoundError: org/rosuda/JRI/Rengine
> com.stephen.crawler.JRI_Interface.<init>(JRI_Interface.java:12)
> org.apache.jsp.Inicio_jsp._jspService(Inicio_jsp.java:124)
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> causa raíz
>
> java.lang.ClassNotFoundException: org.rosuda.JRI.Rengine
> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
> com.stephen.crawler.JRI_Interface.<init>(JRI_Interface.java:12)
> org.apache.jsp.Inicio_jsp._jspService(Inicio_jsp.java:124)
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我想念一下吗?我想我已经配置好了......
非常感谢。
答案 0 :(得分:0)
对于Tomcat 6,Web应用程序的 / WEB-INF / classes 目录中的所有解压缩的类和资源,以及 / WEB-INF /下的JAR文件中的类和资源您的Web应用程序的lib 目录对此Web应用程序可见,但对其他应用程序不可见。
服务器环境按以下顺序初始化:
您的servlet / webappX / jsp可能需要粗体目录中的类或jar。您的服务器似乎已为Tomcat / jsp正确配置,因为它在您的代码/配置中显示错误。正确运行REngine的代码允许使用命令行或env CLASSPATH,但是从Tomcat或其他Web服务器来看并非如此简单。希望它只是复制REngine jar的问题,尽管你可能需要调整它的配置。
GL