gpt4 book ai didi

java - Freemarker 配置问题(Maven 编译失败)

转载 作者:行者123 更新时间:2023-11-29 03:31:28 33 4
gpt4 key购买 nike

我正在做一个使用 freemarker 的项目,我需要做这样的调用:

messageContent.append(FreeMarkerTemplateUtils.processTemplateIntoString(freemarkerConfig.getConfiguration().getTemplate("sampleTemplate.ftl"), model));

但是当我尝试执行 mvn clean package 时,我得到了

"cannot access freemarker.template.Configuration [ERROR] class file for freemarker.template.Configuration not found".

当我尝试显式创建配置对象 (Configuration config = new Configuration()) 时,Eclipse 正如预期的那样建议我导入“freemarker.template.Configuration”。我导入它,错误在 Eclipse 中消失了,但是当我再次尝试执行 mvn clean package 时,我遇到构建失败,提示“package freemarker.template does not exist”。

我的 pom 文件有:

<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.20</version>
<scope>runtime</scope>
</dependency>

我还需要做其他事情吗?提前致谢!

最佳答案

您使用了错误的依赖范围。 runtime 范围不用于编译。来自文档:

This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

因此将作用域更改为compile

<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.20</version>
<scope>compile</scope>
</dependency>

参见 maven dependency scope.

关于java - Freemarker 配置问题(Maven 编译失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18003124/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com