我在我的本地机器上运行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
答案 0 :(得分:1)
因此出于某种原因,无头显示器(至少在我们的Linux发行版上)的默认大小为0.这会导致错误,然后才能手动调整webfigure的大小。所以最终修复是:
set(f,'pos',[0 0 100 100]);