关于我目前的做法,请参阅此主题。它在一段时间内运行良好,我认为所有问题都已解决。但是,当我在不同的文件夹中构建 jar 时,会抛出“找不到模板 index.ftl”。我jar xf xxx.jar
用来解压目标jar,发现templates文件夹下的*.ftl已经被压缩到那个jar里了。
我在这里尝试将以下配置添加到 pom.xml 中的解决方案,但没有奏效。
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>com.gearon.app.App</mainClass>
</manifest>
</archive>
<includes>
<include>**/*.class</include>
<include>**/*.jdo</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.ftl</include>
</includes>
</configuration>
</plugin>
OP还说:
更好的是,我完全删除了配置标签,它仍然有效。我认为这是在我发现 .properties 文件和我在类路径上需要的其他东西需要在 src/main/resources 而不是 src/main/java 之前的残余
我想尝试将模板/xxx.ftl 放在 src/main/resources 而不是 src/main/java/com/gearon/app/templates/*.ftl。
但是加载模板的方式应该改变吧?目前,它是
cfg.setClassForTemplateLoading(Config.class, "/templates");
那么问题来了,怎么改呢?或者,如果我上面的理解完全错误,那么将模板放入 jar 并确保该 jar 中的类可以找到这些模板的最佳做法是什么?
Qyouu
相关分类