问题描述
我需要在服务器端运行.less文件,环境:Tomcat7.X、MyEclipse、并且按照搜索资料:1、在Tomcat的lib目录下放了:apache-commons-logging.jarlog4j-1.2.17.jarcommons-lang-2.6.jarjs.jarlesscss-engine-1.3.0.jarlesscss-servlet-1.3.0.jar这6个jar文件2、在web.xml中配置了:<servlet><servlet-name>less</servlet-name><servlet-class>com.asual.lesscss.LessServlet</servlet-class><init-param><param-name>compress</param-name><param-value>false</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>less</servlet-name><url-pattern>*.less</url-pattern></servlet-mapping>然后访问:http://localhost:8080/test/test.less,报以下错误:2014-8-1316:35:39org.apache.catalina.core.StandardWrapperValveinvoke严重:Servlet.service()forservlet[less]incontextwithpath[/Test_Less]threwexception[java.lang.NullPointerException]withrootcausejava.lang.NullPointerExceptionatorg.mozilla.javascript.Context.call(Context.java:499)atcom.asual.lesscss.LessEngine.call(LessEngine.java:148)atcom.asual.lesscss.LessEngine.compile(LessEngine.java:121)atcom.asual.lesscss.LessEngine.compile(LessEngine.java:114)atcom.asual.lesscss.LessResource.getContent(LessResource.java:46)atcom.asual.lesscss.ResourceServlet.getResourceContent(ResourceServlet.java:128)atcom.asual.lesscss.ResourceServlet.service(ResourceServlet.java:171)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:728)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)atorg.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)atorg.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)atorg.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)atorg.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)atorg.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2430)atorg.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2419)atjava.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)atjava.lang.Thread.run(Thread.java:619)
解决方案
解决方案二:
哪位有配置过相同的,请给指点下是哪里出了问题哦~
解决方案三:
com.asual.lesscss.ResourceServlet.service(ResourceServlet.java:171)这个类是自己写的吗?检查下代码
解决方案四:
不是自己写的,引用的jar包
解决方案五:
servlet配置的没有问题<servlet-class>com.asual.lesscss.LessServlet</servlet-class><init-param><param-name>compress</param-name><param-value>false</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>less</servlet-name><url-pattern>*.less</url-pattern></servlet-mapping>
<init-param><param-name>compress</param-name><param-value>false</param-value></init-param>servlet启动时候的初始化参数<load-on-startup>1</load-on-startup>加载时机反编译下jarcom.asual.lesscss.LessEngine.call(LessEngine.java:148)com.asual.lesscss.LessEngine.compile(LessEngine.java:121)com.asual.lesscss.LessEngine.compile(LessEngine.java:114)com.asual.lesscss.LessResource.getContent(LessResource.java:46)com.asual.lesscss.ResourceServlet.getResourceContent(ResourceServlet.java:128)com.asual.lesscss.ResourceServlet.service(ResourceServlet.java:171)看看里面的错误原因,是哪个参数为空了,是缺少了哪个初始化参数还是什么原因
解决方案六:
直接对less转css。engine.compile(newFile("D:/fonts.less"),newFile("D:/fonts.css"));QQ群14471754