如何从源代码构建 freemarker?

Posted

技术标签:

【中文标题】如何从源代码构建 freemarker?【英文标题】:How to build freemarker from sources? 【发布时间】:2021-10-07 17:43:57 【问题描述】:

我有一个项目 git clone --depth 1 --branch v2.3.30 https://github.com/apache/freemarker.git 并想从源代码构建它。为此我发出一个命令

ant jar

有以下输出

└─$ ant -version                                                                                                                                         1 ⨯
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Apache Ant(TM) version 1.10.9 compiled on December 25 1969
                                                                                                                                                             
┌──(katya12㉿kali)-[/home/…/prostor/offline/ito-kpo-mka/freemarker]
└─$ ant jar     
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Buildfile: /home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build.xml
     [copy] Copying 1 file to /home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build
   [delete] Deleting: /home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build/version.properties.tmp

_autoget-deps:
     [copy] Copying 1 file to /home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build
   [delete] Deleting: /home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build/version.properties.tmp

_autoget-deps-condition-workaround:
     [copy] Copying 1 file to /home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build
   [delete] Deleting: /home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build/version.properties.tmp

update-deps:
     [echo] Getting dependencies...
     [echo] -------------------------------------------------------

BUILD FAILED
/home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build.xml:968: The following error occurred while executing this line:
/home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build.xml:977: The following error occurred while executing this line:
/home/katya/work/prostor/offline/ito-kpo-mka/freemarker/build.xml:985: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -/usr/share/ant/lib
        -/home/katya12/.ant/lib
        -a directory added on the command line with the -lib argument


Total time: 0 seconds

我不知道这是什么意思。你能不能告诉我?是否可以以某种方式使用 ANT 或 IVY 构建源代码?谢谢!

【问题讨论】:

【参考方案1】:

按照GitHub page上的指南进行操作

构建 FreeMarker

如果您还没有,请下载源版本,或从源代码存储库中查看 FreeMarker。在此处查看存储库位置:https://freemarker.apache.org/sourcecode.html

您需要安装 JDK 8(不是 JDK 9!)、Apache Ant(用 1.9.6 测试)和 Ivy(用 2.5.0 测试)。要安装 Ivy(但要确保它尚未安装),请发出 ant download-ivy;它会在 ~/.ant/lib 下复制 Ivy。 (或者,您可以手动将 ivy-.jar 复制到 Ant home lib 子文件夹中。)

建议将 build.properties.sample 复制到 build.properties 中,并编辑其内容以适合您的系统。 (尽管没有 build.properties 文件,基本的 jar 构建也应该成功。)

要构建freemarker.jar,只需在项目根目录下发出ant,它应该会自动下载所有依赖项并构建freemarker.jar。 (依赖项将被缓存到项目的 .ivy/cache 子目录中。)

要测试您的构建,请发出 ant test。

要生成文档,请发出 ant javadoc 和 ant manualOffline。

【讨论】:

以上是关于如何从源代码构建 freemarker?的主要内容,如果未能解决你的问题,请参考以下文章

Freemarker/Velocity - 日期操作

网页静态化FreeMarker的使用

Spring mvc整合freemarker详解

Spring mvc整合freemarker详解

Spring mvc整合freemarker详解

Spring mvc整合freemarker详解