运行 ANT 脚本时出现 DITA OpenToolkit 2.1.1 build.xml “BUILD FAILED”错误

Posted

技术标签:

【中文标题】运行 ANT 脚本时出现 DITA OpenToolkit 2.1.1 build.xml “BUILD FAILED”错误【英文标题】:DITA OpenToolkit 2.1.1 build.xml "BUILD FAILED" error when running ANT script 【发布时间】:2016-01-19 13:44:37 【问题描述】:

DITA 输出目标

我想使用 ANT 脚本将自定义 CSS 样式表添加到我的 DITA 主题模型(请参阅以下代码):

ANT 脚本代码

我的 ANT 脚本:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- ==================
  Web Output Custom CSS 
  ==================-->
<project name="grid_web_css"default="grids.grid_web_css" basedir=".">

    <property name="dita.dir" location="$basedir$file.separator..$file.separator..$file.separator.."/>
    <property name="css.output.dir" value="$dita.dir$file.separatorprojects$file.separatorcss-projects$file.separatorant-scripts$file.separatorout$file.separatorex-ant-understanding-css"/>
    <property name="the.input.dir" value="$dita.dir$file.separatorprojects$file.separatorcss-projects"/>
    <property name="css.source.dir" location="$dita.dir$file.separatorprojects$file.separatorcss-projects$file.separatorshared-assets"/>
    <target name="grids.grid_web_css" depends="clean.grids.grid_web_css">
        <ant antfile="$dita.dir/build.xml">
            <property name="args.input" location="$dita.dir$file.separatorprojects$file.separatorcss-projects$file.separatorunderstanding_css.ditamap"/>
            <property name="input.dir" location="$the.input.dir"/>
            <property name="output.dir" location="$css.output.dir"/>
            <property name="transtype" value="html5"/>
            <property name="args.cs-s-root" location="$css.source.dir"/>
            <property name="args.css" value="$css.source.dir$file.separatorweb-css-grids.css"/>
            <property name="args.csspath" value="$css.output.dir/css"/>
            <property name="args.copycss" value="yes"/>
            <property name="processor" value="saxon"/>
            <property name="classpath" value="$dita.dir$file.separatorlib$file.separatorsaxon.jar"/>
        </ant>
        <copy todir="$css.output.dir/css">
            <fileset dir="$css.source.dir"/>
        </copy>
    </target>
    <target name="clean.grids.grid_web_css" description="remove the sample web output">
        <delete dir="$css.output.dir"/>
    </target>
</project>

问题

根据下面的终端输出,创建目录并找到并执行 build.xml 文件。然而,目录中实际上没有生成任何内容,我无法隔离问题。

终端输出

lingeringcode@Linger:~/dita-ot-2.1.1$ ant -f '/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/ant_grid_web_css.xml' 
Buildfile: /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/ant_grid_web_css.xml

clean.grids.grid_web_css:
   [delete] Deleting directory /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/out/ex-ant-understanding-css

grids.grid_web_css:

init:

dita2html5.init:

check-arg:
    [mkdir] Created dir: /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/out/ex-ant-understanding-css
    [mkdir] Created dir: /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/temp/temp20151020094428144

log-arg:
     [echo] *****************************************************************
     [echo] * basedir = /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts
     [echo] * dita.dir = /home/lingeringcode/dita-ot-2.1.1
     [echo] * transtype = html5
     [echo] * tempdir = /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/temp/temp20151020094428144
     [echo] * outputdir = /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/out/ex-ant-understanding-css
     [echo] * clean.temp = true
     [echo] * DITA-OT version = 2.1.1
     [echo] * XML parser = Xerces
     [echo] * XSLT processor = Saxon
     [echo] * collator = JDL
     [echo] *****************************************************************
     [echo] #Ant properties
     [echo] #Tue Oct 20 09:44:29 CDT 2015
     [echo] args.copycss=yes
     [echo] args.css=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/shared-assets/web-css-grids.css
     [echo] args.csspath=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/out/ex-ant-understanding-css/css
     [echo] args.cs-s-root=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/shared-assets
     [echo] args.grammar.cache=yes
     [echo] args.input=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/understanding_css.ditamap
     [echo] args.logdir=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/out/ex-ant-understanding-css
     [echo] args.xml.systemid.set=yes
     [echo] dita.dir=/home/lingeringcode/dita-ot-2.1.1
     [echo] dita.plugin.com.sophos.tocjs.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/com.sophos.tocjs
     [echo] dita.plugin.org.dita.base.dir=/home/lingeringcode/dita-ot-2.1.1
     [echo] dita.plugin.org.dita.docbook.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.docbook
     [echo] dita.plugin.org.dita.eclipsecontent.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.eclipsecontent
     [echo] dita.plugin.org.dita.eclipsehelp.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.eclipsehelp
     [echo] dita.plugin.org.dita.htmlhelp.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.htmlhelp
     [echo] dita.plugin.org.dita.javahelp.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.javahelp
     [echo] dita.plugin.org.dita.odt.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.odt
     [echo] dita.plugin.org.dita.pdf2.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.pdf2
     [echo] dita.plugin.org.dita.specialization.dita11.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.specialization.dita11
     [echo] dita.plugin.org.dita.specialization.eclipsemap.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.specialization.eclipsemap
     [echo] dita.plugin.org.dita.troff.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.troff
     [echo] dita.plugin.org.dita.wordrtf.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.wordrtf
     [echo] dita.plugin.org.dita.xhtml.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.xhtml
     [echo] dita.plugin.org.oasis-open.dita.v1_2.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.oasis-open.dita.v1_2
     [echo] dita.temp.dir=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/temp/temp20151020094428144
     [echo] *****************************************************************

build-init:

preprocess.init:
     [echo] *****************************************************************
     [echo] * input = /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/understanding_css.ditamap
     [echo] *****************************************************************

gen-list:

BUILD FAILED
/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/ant_grid_web_css.xml:18: The following error occurred while executing this line:
/home/lingeringcode/dita-ot-2.1.1/build.xml:42: The following error occurred while executing this line:
/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.base/build_preprocess.xml:78: java.lang.ClassNotFoundException: org.dita.dost.module.GenMapAndTopicListModule
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191)
    at org.apache.tools.ant.IntrospectionHelper$6.set(IntrospectionHelper.java:1095)
    at org.apache.tools.ant.IntrospectionHelper$AttributeSetter.setObject(IntrospectionHelper.java:1493)
    at org.apache.tools.ant.IntrospectionHelper.setAttribute(IntrospectionHelper.java:411)
    at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:528)
    at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:464)
    at org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:592)
    at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:358)
    at org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:204)
    at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
    at org.apache.tools.ant.Task.perform(Task.java:347)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:440)
    at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:440)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.Main.runBuild(Main.java:851)
    at org.apache.tools.ant.Main.startAnt(Main.java:235)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

从上面的输出中可以看出,错误输出在“BUILD FAILED”行之后开始。

我的故障排除尝试

我发现其他人也有类似问题:https://groups.yahoo.com/neo/groups/dita-users/conversations/topics/38045。然而,当我添加属性并为 Saxon 设置环境变量时,我得到了相同的输出。 我还测试了 Open Toolkit 中的其他 ant 脚本示例,并收到了相同的错误消息。

寻求帮助

我想我要么错误地设置了我的环境变量,要么我什至无法想象导致这个问题的原因;因此,我需要对这个问题多加注意。

因此,也许有人可以帮助我了解我应该如何设置我的 java + ant + saxon + xalan——我还没有找到关于这个过程的好的文档。另外,如何验证我拥有让它工作所需的一切。或者,我很想帮忙看看是不是别的。

仅供参考,我使用的是 DITA-OT 2.1.1。这是我在 Github 上的主题模型的链接:https://github.com/lingeringcode/css-projects。

感谢任何帮助! :-)

更新

FTR,dita 命令与-D 参数一起工作,如下:

:~/dita-ot-2.1.1$ dita -f html5 -i 'projects/css-projects/understanding_css.ditamap' \
    -o '项目/css-projects/ex-understanding-css' \
    -Dargs.cs-s-root='projects/css-projects/shared-assets'\
    -Dargs.css='$cs-s-root/web-css-grids.css'\
    -Dargs.csspath='css'\
    -Dargs.copycss='是'

我还重置了我的 CLASSPATH 变量,确保确实找到了 dost.jar。再次运行 ant 脚本后,我收到一条新的 BUILD FAILED 错误消息(耶,进度?!),如下所示:

lingeringcode@Linger:~/dita-ot-2.1.1/projects/css-projects$ ant -f '/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/ant_grid_web_css.xml ' 构建文件:/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/ant_grid_web_css.xml clean.grids.grid_web_css: [delete] 删除目录/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ex-ant-understanding-css grids.grid_web_css: 在里面: dita2html5.init: 检查参数: [mkdir] 创建目录:/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ex-ant-understanding-css [mkdir] 创建目录:/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/temp/temp20151022130204394 日志参数: [回声] ***************************************************** ****************** [回声] * basedir = /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts [回声] * dita.dir = /home/lingeringcode/dita-ot-2.1.1 [回声] * 转换 = html5 [回声] * tempdir = /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/temp/temp20151022130204394 [echo] * outputdir = /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ex-ant-understanding-css [回声] * clean.temp = true [回声] * DITA-OT 版本 = 2.1.1 [echo] * XML 解析器 = Xerces [echo] * XSLT 处理器 = Saxon [回声] * 整理者 = JDL [回声] ***************************************************** ****************** [echo] #蚂蚁属性 [回声] #Thu Oct 22 13:02:05 CDT 2015 [回声] args.copycss=yes [回声] args.css=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/shared-assets/web-css-grids.css [回声] args.csspath=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ex-ant-understanding-css/css [回声] args.cs-s-root=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/shared-assets [回声] args.grammar.cache=yes [回声] args.input=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/understanding_css.ditamap [回声] args.logdir=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ex-ant-understanding-css [回声] args.xml.systemid.set=yes [回声] dita.dir=/home/lingeringcode/dita-ot-2.1.1 [回声]dita.plugin.com.sophos.tocjs.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/com.sophos.tocjs [回声] dita.plugin.org.dita.base.dir=/home/lingeringcode/dita-ot-2.1.1 [回声] dita.plugin.org.dita.docbook.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.docbook [回声] dita.plugin.org.dita.eclipsecontent.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.eclipsecontent [回声] dita.plugin.org.dita.eclipsehelp.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.eclipsehelp [回声] dita.plugin.org.dita.htmlhelp.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.htmlhelp [回声] dita.plugin.org.dita.javahelp.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.javahelp [回声] dita.plugin.org.dita.odt.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.odt [回声]dita.plugin.org.dita.pdf2.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.pdf2 [回声]dita.plugin.org.dita.specialization.dita11.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.specialization.dita11 [回声]dita.plugin.org.dita.specialization.eclipsemap.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.specialization.eclipsemap [回声] dita.plugin.org.dita.troff.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.troff [回声]dita.plugin.org.dita.wordrtf.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.wordrtf [回声] dita.plugin.org.dita.xhtml.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.xhtml [回声]dita.plugin.org.oasis-open.dita.v1_2.dir=/home/lingeringcode/dita-ot-2.1.1/plugins/org.oasis-open.dita.v1_2 [回声]dita.temp.dir=/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/temp/temp20151022130204394 [回声] ***************************************************** ****************** 构建初始化: 预处理.init: [回声] ***************************************************** ****************** [回声] * 输入 = /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/understanding_css.ditamap [回声] ***************************************************** ****************** 基因列表: [gen-list] 无法从配置中读取打印转换类型,使用默认值。 [gen-list] 使用 Xerces 语法池进行 DTD 和模式缓存。 [gen-list] 处理文件:/home/lingeringcode/dita-ot-2.1.1/projects/css-projects/understanding_css.ditamap 构建失败 /home/lingeringcode/dita-ot-2.1.1/projects/css-projects/ant-scripts/ant_grid_web_css.xml:24:执行此行时出现以下错误: /home/lingeringcode/dita-ot-2.1.1/build.xml:42:执行此行时出现以下错误: /home/lingeringcode/dita-ot-2.1.1/plugins/org.dita.base/build_preprocess.xml:78:无法运行管道:无法加载消息配置文件:找不到消息配置文件

现在,它报告“失败的管道”+ 无法加载某些配置文件。有什么想法吗?

【问题讨论】:

您还需要这方面的帮助吗?如果您遇到另一个错误,请不要更新您的原始问题,而是创建一个新问题。否则不会通知任何人。 嗨,@xephon,感谢您与我联系。我没有时间回到这个特定的方法。相反,我使用了命令行参数。如果我真的回到这个方法,我一定会考虑到这一点。谢谢! 【参考方案1】:

这是重要信息:

java.lang.ClassNotFoundException: org.dita.dost.module.GenMapAndTopicListModule

这表明 dost.jar 丢失。您必须将 DITA 库传递给 Ant,否则脚本将无法运行。

您可以阅读文档Building output using Ant 如何调用 Ant。

也许您根本不需要使用 Ant 调用您的转换。 dita 命令有一个 args.css 参数,它可能会实现您想要实现的目标。请看Ant parameters: Common HTML-based transformations。

【讨论】:

dita 命令与 -D 参数一起使用。但是,我仍然想看看是否可以让 ant 也能正常工作。我重新定义了我的环境变量/类路径以获得良好的衡量标准。 FTR,我正在关注(并修改)DITA-OT 1.5.4 中的以下文档,因为我找不到 2.1:http://dita-ot.sourceforge.net/1.5.4/readme/DITA-installation.html。我已修改 CLASSPATH 文件名以匹配 2.1.1。然而,它仍然没有找到 dost.jar。您有更新文档的链接吗? 我将进一步修改我如何设置 Ant 和 Saxon。我想知道我是否在某处犯了错误/没有最新版本等。感谢您的指导,@xephon! 我“修复”了 dost.jar 错误,但有了一个新错误。关于这个“管道”错误消息的任何想法? 嗯...你读过Installing the distribution package吗? 文档说:“可选:将 bin 目录的绝对路径添加到 PATH 系统变量。这定义了从命令行运行 dita 命令所需的环境变量。提示:此步骤是推荐,因为它允许从文件系统上的任何位置运行 dita 命令,并且可以更轻松地从任何文件夹转换 DITA 内容。"

以上是关于运行 ANT 脚本时出现 DITA OpenToolkit 2.1.1 build.xml “BUILD FAILED”错误的主要内容,如果未能解决你的问题,请参考以下文章

为啥在 cmd 中运行 ant sonar 命令时出现错误?

使用 ant-cli 部署生产 mobilefirst 7.1 环境时出现 404 错误

java web 编译时出现错误

Android:使用 Ant Release 构建 apk 时出现问题

运行 Pig 脚本时出现异常

尝试运行 ESLint 脚本时出现“SyntaxError: Unexpected token ”