Velocity Unable to find resource

在maven构建的Velocity项目中遇到资源找不到的错误,当尝试模块化引入时,Velocity.getTemplate方法抛出异常。解决方案包括调整maven的build配置或者采用变量编译模板的方法来避免资源定位问题。
摘要由CSDN通过智能技术生成

在maven的velocity项目中将resources下的模板资源文件打包。

将velocity模块化引入到其它项目时报Unable to find resource '';Velocity.getTemplate获取资源文件出错!

VelocityContext velocityContext = new VelocityContext(context.toMap());
Template template = Velocity.getTemplate("mybatis\\Model.java.vm", "UTF-8")
try (StringWriter writer = new StringWriter()) {
    template.merge(velocityContext, writer);
    return writer.toString();
} catch (IOException e) {
    e.printStackTrace();
}

解决方案1:

配置maven的build(可选择其它方式配置)

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>

即可。

解决方案2:

使用变量编译模板。

final String templateContent = "package com.sicex.db.entity.${table.classPackage};
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值