如何包括 Ant flaka jar? [英] How to include Ant flaka jar?

查看:22
本文介绍了如何包括 Ant flaka jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写 ant 脚本并使用 Ant flaka jar 做一些工作.

I am writing ant scripts and using Ant flaka jar to do some work.

但是 flaka 不能像其他外部 Ant 库一样工作.

But flaka doesn't work as other external Ant lib.

例如,如果我需要包含 ant-contrib:

For example, if I need to include ant-contrib:

  <taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
        <pathelement location="../../lib/ant-contrib.jar"/>
  </classpath>
  </taskdef>

最重要的是,我可以指定 jar 所在的位置.

Most importantly, I can specify where the jar is located.

但是对于flaka,我没有看到这样的事情.在官网上,他们只是告诉用户将flaka jar下载到Ant安装文件夹中.

But for flaka, I don't see such thing. In the official website, they just tell user to download flaka jar to Ant installation folder.

我想使用flaka jar时如何指定它在哪里?

How can I specify where is the flaka jar when I want to use it?

推荐答案

首先是一些一般性的建议.对于 ant,任​​何外部库都必须在视线范围内,这意味着在路径上.
最原始的方法是将您的 ant 插件放在 $ANT_HOME/lib 中,但这会污染"您的 ant 安装.
将您的外部库放在它自己的位置,例如/ant_xtralibs 并通过 Ant_ARGS 使用 -lib 参数.
Flaka 手册第 2 节对此有一些说明,Ant 手册.

First of all some general recommendation. Any external lib has to be in sight for ant, means on path.
The most primitive approach is to put your ant addons in $ANT_HOME/lib, but that 'pollutes' your ant installation.
Put your external libs in it's own location, f.e. /ant_xtralibs and use the -lib parameter via Ant_ARGS.
The Flaka manual section 2 has some notes about that, more details in the Ant manual.

您处理 antcontrib 的示例使用通过 taskdef 资源的传统方法..
现代推荐的方法是使用 XML 命名空间声明,正如 Flaka 手册在第 2 节之前提到的
:
因此显示的所有构建文件片段都假定构建文件包含以下 XML 命名空间声明"

Your example dealing with antcontrib uses the traditional approach via taskdef resource..
The modern - recommended - way is to use a XML namespace declaration, as the Flaka Manual mentions
right before section 2 :
"Thus all build file snippets shown assume that the build file contains the following XML namespace declaration"

也可以通过 taskdef 以传统方式使用 Flaka:

It's also possible to use Flaka via taskdef the traditional way:

<project>
  <taskdef resource="it/haefelinger/flaka/antlib.xml">
   <classpath>
    <pathelement location="/home/rosebud/flaka/ant-flaka-1.02.02.jar"/>
   </classpath>
  </taskdef>

  <!-- when on path via -lib or ANT_ARGS it's enough to use : -->
  <taskdef resource="it/haefelinger/flaka/antlib.xml"/>

  <logo>
   Hello, #{property['ant.file'].tofile.name}
  </logo>

</project>

输出

Trying to override old definition of datatype filterset
Trying to override old definition of task fail
Trying to override old definition of task echo
[logo] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
[logo] :                               Hello, demo.xml                                :
[logo] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

注意以试图覆盖.."开头的行那是因为 Flaka 扩展了一些蚂蚁任务

note the lines starting with "Trying to override.." That's because of Flaka extends some ant tasks

但是如果你把 Flaka 放在它自己的命名空间中:

but if you put Flaka in it's own namespace :

<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">
 <fl:logo>
  Hello, #{property['ant.file'].tofile.name}
 </fl:logo>
</project>

输出

[fl:logo] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
[fl:logo] :                               Hello, demo.xml                                :
[fl:logo] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

不再试图覆盖..."意味着不再与 ant 自己的任务发生冲突,因为 Flaka 驻留在它自己的命名空间中

no more "Trying to override..." means no more collision with ant's own tasks, as Flaka resides in it's own namespace

简单来说:
1) 使用 ANT_ARGS 将您的 extralibs(Flaka .. 等)带入游戏
2) 使用现代的命名空间声明方式

So to make it short :
1) use ANT_ARGS to bring your extralibs (Flaka .. etc.) in the game
2) use the modern way of Namespace declaration

EDIT 在评论要求结合类路径的命名空间后EDIT

EDIT after comment asking for namespace combined with classpath EDIT

是的,请参阅 Ant 手册以了解有关 antlib 的详细信息,尤其是部分
从构建文件内部加载 antlib",对于 Flaka,您可以使用以下内容:

yes that works, see Ant manual for details about antlib, especially the section
"Load antlib from inside of the buildfile", for Flaka you would use something like :

<project xmlns:fl="antlib:it.haefelinger.flaka">
 <taskdef uri="antlib:it.haefelinger.flaka"
  resource="it/haefelinger/flaka/antlib.xml"
  classpath="path/to/flaka.jar"/>

但我相信您仍然没有获得使用 $ANT_ARGS 的优势
只需使用一些脚本来启动您的 ant 脚本,例如:

but i believe you still didn't get the advantages of using $ANT_ARGS
simply use some script to start your ant scripts, f.e. :

Windows
设置 JAVA_HOME=C:\java\jdk\1.6.0_26
设置 ANT_HOME=C:\ant
设置 ANT_ARGS=-lib C:\ant_xtralibs;C:\ant_testlibs
set PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin;C:\cvsnt

for Windows
set JAVA_HOME=C:\java\jdk\1.6.0_26
set ANT_HOME=C:\ant
set ANT_ARGS=-lib C:\ant_xtralibs;C:\ant_testlibs
set PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin;C:\cvsnt

::默认
调用 ant -f %1

:: default
call ant -f %1

::调试
::调用 ant -debug -f %1
...等

:: debug
::call ant -debug -f %1
... etc.

对于 Linux/Unix - 不要忘记 ANT_ARGS 行上的引号!
...
ANT_ARGS="-lib/usr/local/ant_xtralibs:/usr/local/ant_testlibs"
导出 ANT_ARGS
...

for Linux/Unix - don't forget the quotationmarks on the ANT_ARGS line !
...
ANT_ARGS="-lib /usr/local/ant_xtralibs:/usr/local/ant_testlibs"
export ANT_ARGS
...

您不再需要将 taskdef 与 classpath 一起使用!!
使用 -lib 选项加载其他库还有另一个好处.
有一些库必须在 Ant 之前加载(例如 BSF、js、xml)
开始解析构建文件.

You don't need to use taskdef with classpath anymore !!
Using the -lib option to load additional libraries has another benefit.
There are some libs which must be loaded before Ant (f.e. BSF, js, xml)
starts parsing the buildfile.

ANT_ARGS 是一个特殊的环境变量.它的内容是自动添加到 Ant 的调用中.

ANT_ARGS is a special environment variable. Its content is automatically added to the invocation of Ant.

-- 其他可能性--

-- Other possibilities --

1)
将那些设置 ANT_ARGS ..."的东西放入 =

1)
put those 'set ANT_ARGS ...' stuff into =

Linux/Unix
$ANT_HOME/bin/ant

Linux/Unix
$ANT_HOME/bin/ant

窗户
%ANT_HOME%/bin/ant.bat

Windows
%ANT_HOME%/bin/ant.bat

缺点=改变ant核心安装,切记
将 ant 安装复制到
之前的更改另一台机器发生了奇怪的事情!

disadvantage = changes the ant core installation, remember
your changes before you copy your ant installation to
another machine and strange things happen !

2)
把你的额外库放在 ${user.home}/.ant/lib
优势 = 每个用户都可以使用自己的一组库

2)
put your extralibs in ${user.home}/.ant/lib
advantage = every user may use his own set of libraries

详情请查阅 Ant 手册:
http://ant.apache.org/manual/running.html#commandline
http://ant.apache.org/manual/running.html#libs

consult the Ant manual for details :
http://ant.apache.org/manual/running.html#commandline
http://ant.apache.org/manual/running.html#libs

这篇关于如何包括 Ant flaka jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆