我在本地机器上运行 matlab,并从 Java 调用以下函数(在 tomcat Web 服务器中运行):
function df = getFig(file)
f = openfig(file,'reuse','invisible');
set(f, 'Color', [1,1,1]);
df = webfigure(f);
close(f);
end
这在本地运行良好,但在我们的无头 unix 网络服务器上运行时,我们会收到此错误:
{Error using set
Width and height must be > 0
Error in
renderwebfigure>@(childHnd,childPos)set(childHnd,'Position',[childPos(1)*parameters.width-clipRect(1)+extraRenderSpace,childPos(2)*parameters.height-clipRect(2)+extraRenderSpace,childPos(3)*parameters.width,childPos(4)*parameters.height])
(line 70)
Error in renderwebfigure>cropFigureAndReturnCData (line 70)
Error in renderwebfigure (line 31)
}
Mar 30, 2012 4:08:17 PM org.apache.catalina.core.ApplicationContext log
INFO: WebFigures: com.mathworks.toolbox.javabuilder.services.ServiceException: com.mathworks.toolbox.javabuilder.services.ServiceException: com.mathworks.toolbox.javabuilder.services.ServiceDispatchTargetException: com.mathworks.toolbox.javabuilder.services.ServiceException: java.lang.reflect.InvocationTargetException
at com.mathworks.toolbox.javabuilder.webfigures.WebFiguresServlet.doGet(WebFiguresServlet.java:161)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mathworks.toolbox.javabuilder.services.ServiceException: com.mathworks.toolbox.javabuilder.services.ServiceDispatchTargetException: com.mathworks.toolbox.javabuilder.services.ServiceException: java.lang.reflect.InvocationTargetException
at com.mathworks.toolbox.javabuilder.webfigures.service.request.WebFigureRenderRequest.process(WebFigureRenderRequest.java:230)
at com.mathworks.toolbox.javabuilder.webfigures.service.request.WebFigureRenderRequest.process(WebFigureRenderRequest.java:38)
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureServiceFactory$WebFigureServiceImpl.processRequest(WebFigureServiceFactory.java:61)
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureServiceFactory$WebFigureServiceImpl.processRequest(WebFigureServiceFactory.java:42)
at com.mathworks.toolbox.javabuilder.webfigures.WebFiguresServlet$1.call(WebFiguresServlet.java:147)
at com.mathworks.toolbox.javabuilder.webfigures.WebFiguresServlet$1.call(WebFiguresServlet.java:145)
at com.mathworks.toolbox.javabuilder.webfigures.WebFiguresServlet.doGet(WebFiguresServlet.java:158)
... 17 more
Caused by: com.mathworks.toolbox.javabuilder.services.ServiceDispatchTargetException: com.mathworks.toolbox.javabuilder.services.ServiceException: java.lang.reflect.InvocationTargetException
at com.mathworks.toolbox.javabuilder.services.StatefulServicePeerCache.dispatch(StatefulServicePeerCache.java:174)
at com.mathworks.toolbox.javabuilder.webfigures.service.request.WebFigureRenderRequest.process(WebFigureRenderRequest.java:221)
... 23 more
Caused by: com.mathworks.toolbox.javabuilder.services.ServiceException: java.lang.reflect.InvocationTargetException
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureBinder$WebFigurePeerImpl.renderImage(WebFigureBinder.java:260)
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureBinder$WebFigurePeerImpl.renderEncoded(WebFigureBinder.java:329)
at com.mathworks.toolbox.javabuilder.webfigures.service.request.WebFigureRenderRequest$1.execute(WebFigureRenderRequest.java:223)
at com.mathworks.toolbox.javabuilder.webfigures.service.request.WebFigureRenderRequest$1.execute(WebFigureRenderRequest.java:221)
at com.mathworks.toolbox.javabuilder.services.StatefulServicePeerCache.dispatch(StatefulServicePeerCache.java:171)
... 24 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureBinder$WebFigurePeerImpl$1.call(WebFigureBinder.java:254)
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureBinder$WebFigurePeerImpl$1.call(WebFigureBinder.java:252)
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureBinder$WebFigurePeerImpl.whileLocked(WebFigureBinder.java:191)
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureBinder$WebFigurePeerImpl.renderImage(WebFigureBinder.java:252)
... 28 more
Caused by: com.mathworks.toolbox.javabuilder.MWException: Error using set
Width and height must be > 0
at com.mathworks.toolbox.javabuilder.internal.MWMCR.mclFeval(Native Method)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.access$600(MWMCR.java:23)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$6.mclFeval(MWMCR.java:833)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$5.invoke(MWMCR.java:731)
at $Proxy4.mclFeval(Unknown Source)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.invoke(MWMCR.java:406)
at com.mathworks.toolbox.javabuilder.webfigures.service.WebFigureServiceMCR.renderwebfigure(WebFigureServiceMCR.java:211)
... 36 more
我使用情节(1:10)生成的其他数字;在两个平台上都可以正常工作。所以看来问题出在 openfig 函数上。此外,如果我在一个不存在的文件的路径中路径我得到一个文件未找到错误,而不是宽度和高度必须> 0 错误
然而,调用它是有效的:
function w = getplot
f = figure('visible', 'off');
plot(1:10);
w = webfigure(f);
close(f);
end