You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Velocity 1.4初始化报错:找不到org.apache.log.format.Formatter类

Velocity 1.4初始化日志类缺失问题解决方案

问题描述

使用Velocity 1.4搭建邮件系统时,初始化引擎出现java.lang.NoClassDefFoundError: org/apache/log/format/Formatter错误,已添加logkit.jar但问题未解决。错误栈如下:

2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - PANIC : Velocity cannot find any of the specified or default logging systems in the classpath, or the classpath doesn't contain the necessary classes to support them. Please consult the documentation regarding logging. Exception : java.lang.NoClassDefFoundError: org/apache/log/format/Formatter
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - Exception in thread "pool-6-thread-1"
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - java.lang.NoClassDefFoundError: org/apache/log/format/Formatter
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at org.apache.velocity.runtime.log.LogManager.createLogSystem(LogManager.java:162)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at org.apache.velocity.runtime.RuntimeInstance.initializeLogger(RuntimeInstance.java:553)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:226)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:461)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:106)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at com.example.mail.Renderer.setVelocityEngine(Renderer.java:32)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at com.example.mail.Renderer.getTemplate(Renderer.java:42)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at com.example.polarion.Util.sendMailForTrigger(Util.java:733)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at com.example.a3.servlet.async.PushEventProcessor.process(PushEventProcessor.java:232)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at com.example.a3.servlet.async.PushEventProcessorThread.run(PushEventProcessorThread.java:52)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
2022-12-19 04:52:11,269 [pool-6-thread-1] WARN - at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

解决方案

1. 匹配正确版本的LogKit依赖

Velocity 1.4官方依赖LogKit 1.0.1版本,高版本LogKit可能调整了包结构,导致org.apache.log.format.Formatter类不存在。确保引入的是LogKit 1.0.1的jar包:

  • 若使用Maven,添加如下依赖:
<dependency>
    <groupId>logkit</groupId>
    <artifactId>logkit</artifactId>
    <version>1.0.1</version>
</dependency>
  • 手动下载的话,确认jar包文件名是logkit-1.0.1.jar,而非其他版本。

2. 验证类路径加载有效性

  • 对于Web项目,确保logkit-1.0.1.jar放在WEB-INF/lib目录下,而非仅添加到IDE的library中(IDE配置不代表运行时类路径生效)。
  • 对于独立应用,检查启动脚本的classpath参数是否包含该jar包,或者确认jar包已加入到JVM的类路径中。

3. 切换至JDK内置日志实现(推荐,适配高版本JDK)

如果仍无法解决,可跳过LogKit,配置Velocity使用JDK自带的java.util.logging,避免依赖第三方日志包:
在Velocity引擎配置中添加以下属性:

VelocityEngine ve = new VelocityEngine();
ve.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.JdkLogChute");
ve.init();

或者在配置文件中设置:

runtime.log.logsystem.class=org.apache.velocity.runtime.log.JdkLogChute

4. 检查JDK版本兼容性

Velocity 1.4发布于2006年,官方仅支持JDK 1.4~1.6。若当前使用JDK 11+等新版本,可能存在底层API兼容问题。如果业务允许,建议升级Velocity至1.7或2.x版本,这些版本对高JDK兼容性更好,且日志实现更灵活。


内容的提问来源于stack exchange,提问作者Ananthu KT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 14:25:18