18

我构建了一个在我的本地主机(tomcat)中运行良好的 web 应用程序。但是当我尝试部署时,velocity 在 init() 中崩溃,在这里留下了这个奇怪的堆栈跟踪(对不起大小):


ERROR [main] (VelocityConfigurator.java:62) - Error initializing Velocity!
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
    at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:589)
    at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:229)
    at org.apache.velocity.app.Velocity.init(Velocity.java:107)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.initVelocity(VelocityConfigurator.java:57)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.configure(VelocityConfigurator.java:42)
    at com.webcodei.velociraptor.VelociListener.contextInitialized(VelociListener.java:26)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.apache.velocity.util.ExceptionUtils.createWithCause(ExceptionUtils.java:67)
    at org.apache.velocity.util.ExceptionUtils.createRuntimeException(ExceptionUtils.java:45)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:133)
    at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85)
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
    ... 33 more
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.(FileOutputStream.java:177)
    at java.io.FileOutputStream.(FileOutputStream.java:102)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:194)
    at org.apache.log4j.FileAppender.(FileAppender.java:109)
    at org.apache.log4j.RollingFileAppender.(RollingFileAppender.java:72)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118)
    ... 35 more
ERROR [main] (VelocityConfigurator.java:63) - java.lang.RuntimeException: Error configuring Log4JLogChute : 
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
    at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:589)
    at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:229)
    at org.apache.velocity.app.Velocity.init(Velocity.java:107)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.initVelocity(VelocityConfigurator.java:57)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.configure(VelocityConfigurator.java:42)
    at com.webcodei.velociraptor.VelociListener.contextInitialized(VelociListener.java:26)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.apache.velocity.util.ExceptionUtils.createWithCause(ExceptionUtils.java:67)
    at org.apache.velocity.util.ExceptionUtils.createRuntimeException(ExceptionUtils.java:45)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:133)
    at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85)
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
    ... 33 more
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.(FileOutputStream.java:177)
    at java.io.FileOutputStream.(FileOutputStream.java:102)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:194)
    at org.apache.log4j.FileAppender.(FileAppender.java:109)
    at org.apache.log4j.RollingFileAppender.(RollingFileAppender.java:72)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118)
    ... 35 more
ERROR [main] (VelocityConfigurator.java:64) - Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
    at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:589)
    at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:229)
    at org.apache.velocity.app.Velocity.init(Velocity.java:107)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.initVelocity(VelocityConfigurator.java:57)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.configure(VelocityConfigurator.java:42)
    at com.webcodei.velociraptor.VelociListener.contextInitialized(VelociListener.java:26)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.apache.velocity.util.ExceptionUtils.createWithCause(ExceptionUtils.java:67)
    at org.apache.velocity.util.ExceptionUtils.createRuntimeException(ExceptionUtils.java:45)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:133)
    at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85)
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
    ... 33 more
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.(FileOutputStream.java:177)
    at java.io.FileOutputStream.(FileOutputStream.java:102)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:194)
    at org.apache.log4j.FileAppender.(FileAppender.java:109)
    at org.apache.log4j.RollingFileAppender.(RollingFileAppender.java:72)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118)
    ... 35 more


有谁知道解决方法?或者至少理解错误?我做了一些谷歌搜索但没有任何线索..只有这个页面面临同样的问题但没有解决方案..

4

6 回答 6

39

Velocity 尝试将日志文件放在启动 Tomcat 的目录中,我相信这实际上是 /。

您可以通过将这些行添加到您的 velocity.properties 来强制 Velocity 记录到 Tomcat 的标准日志:

runtime.log.logsystem.class=org.apache.velocity.runtime.log.SimpleLog4JLogSystem
runtime.log.logsystem.log4j.category=velocity
runtime.log.logsystem.log4j.logger=velocity

velocity.properties 应该进入 /WEB-INF/velocity.properties 但您可以在 web.xml 中的 servlet 定义中覆盖它。

如果您通过属性而不是 velocity.properties 来初始化 Velocity:

VelocityEngine engine = new VelocityEngine();

Properties props = new Properties();
props.put("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
props.put("runtime.log.logsystem.log4j.category", "velocity");
props.put("runtime.log.logsystem.log4j.logger", "velocity");

engine.init(props);

在这里阅读更多:

http://velocity.apache.org/engine/devel/developer-guide.html#usinglog4jwithexistinglogger

和这里:

http://minaret.biz/tips/tomcatLogging.html#velocity

于 2012-08-18T06:48:38.543 回答
10

我认为这条线有答案。看起来创建velocity.log 文件时出现问题。你的配置文件是什么样的?

Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
于 2009-05-11T19:50:50.313 回答
4

似乎尝试打开日志文件的进程没有这样做的权限:

Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
于 2009-05-11T19:48:40.503 回答
1

我也有同样的问题,但我能够解决此问题,将默认日志文件覆盖为自定义日志文件。只需在调用评估函数的方法中添加这 3 行代码。

Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,"org.apache.velocity.runtime.log.Log4JLogChute");

Velocity.setProperty("runtime.log.logsystem.log4j.logger","com.mindtree.igg.website.email.TemplateMergeUtilVelocityImpl");

VelocityContext velocityContext = new VelocityContext(parameters);

这是解决它的一种方法,即不使用属性文件。

于 2014-04-22T11:19:00.227 回答
1

我的代码遇到了完全相同的问题,经过数小时的谷歌搜索,我决定在我的项目中添加一些其他 Velocity 库。我的项目只有 apache-velocity jar 文件,然后从这里,我还将 Velocity-Dep 添加到我的 Maven 项目和 Yesssssssssss!胜利!

于 2016-03-31T19:54:56.327 回答
-1

我遇到了同样的问题,并写了一篇描述性博客,其中包含可能的原因和解决方案。这是链接

于 2013-07-02T17:43:05.433 回答