Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打包问题 #4

Open
NiuTFei opened this issue Oct 28, 2022 · 6 comments
Open

打包问题 #4

NiuTFei opened this issue Oct 28, 2022 · 6 comments

Comments

@NiuTFei
Copy link

NiuTFei commented Oct 28, 2022

打包之后运行报错:
Caused by: java.io.FileNotFoundException: src/main/resources/templates does not exist.
是不是需要修改一下模版配置文件呢,还是有其他解决办法。

@KweilinFang
Copy link

怎么解决的?如果解决了告知一下。我也学习学习

@NiuTFei
Copy link
Author

NiuTFei commented Nov 1, 2022

我看到一个文章是解决类似的问题的,https://www.jb51.net/article/243231.htm,但是没有尝试

@Bemege
Copy link

Bemege commented Nov 2, 2022

参考 #8 (comment)

@gongwx
Copy link

gongwx commented Nov 11, 2022

换一种加载方式即可 cfg.setClassForTemplateLoading(this.getClass(), "/templates");

@zhaohaoyun
Copy link

问题的原因是加载模板目录方法错误,setDirectoryForTemplateLoading在IDE运行没问题,但是打包发布以后没办法从jar包直接加载文件路径
正确解决方法:
cfg.setDirectoryForTemplateLoading(new File("src/main/resources/templates"));
修改为
cfg.setClassForTemplateLoading(this.getClass(),"templates");

项目中只要修改两个地方
com.yupi.sqlfather.config.FreeMarkerConfigurationConfig
com.yupi.sqlfather.FreeMarkerTest

@thxcn
Copy link

thxcn commented Apr 20, 2023

非常感谢,我成功了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants