I'm looking for a way to include a .jar from within an Ant file so I can use it straight away and call its methods in my targets.
In my case it's ant-contrib-1.0b3.jar
.
相关问题
- How can I have my ant task pass or fail based on t
- Ant inheriting Maven properties
- How can I zip multiple folders individually with a
- Class in jar not found at runtime, but was used to
- Regex to select last line in a multi-line string
相关文章
- Passing command line arguments to Java via ant bui
- ANT - Could not load a dependent class com/jcraft/
- library resolve to a path with no project.properti
- ant file that depends on another ant file
- android-sdk/tools/ant/build.xml:698: null returned
- ant jar's mainclass
- Integrate Ant builder into Eclipse: Error “Variabl
- How can I avoid this Ant Build error?
The best solution is to integrate the apache ivy dependency manager. Ivy can be used to manage all your build classpaths Maven-style!
Example
ivy.xml
This file describes your project's 3rd party dependencies. Ivy uses configurations to logically group files together. In your case note the special "build" configuration uses to configure ANT tasks needed by the build:
Note:
build.xml
Notes:
The best way is to put the Ant-Contrib jarfile inside you project. For example, let's say the
build.xml
is in the root of your project. Create a directory calledant.lib\ant-contrib
inside your project, then put theant-contrib*.jar
in this folder. You can use this method for other optional Ant tasks that you might need (for example, Ivy, Findbugs, Cobrrtura, etc).Then, in your
build.xml
file, you can do this:I like doing it this way because the optional jars with the tasks are included with the project. If you check everything into your version control system, someone can checkout your code, and do the build without downloading Ant-Contrib and installing it themselves.
You can define an XML namespaces. This gives your Ant-Contrib tasks a prefix in order to avoid task name collisions in case you use other optional ant tasks that have the same task name. Plus, it alerts users that this is not a standard Ant task.
If you use an XML namespace, you need to put a XMLNS declaration in your
<project>
heading. This will contain a URI that will connect your Ant Contrib tasks to your XML namespace. For example, theac:
namespace is for all Ant Contrib tasks:What this does is match the XML namespace (xmlns) of
ac
with the URIhttp://ant-contrib.sourceforge.net
. The URI could be anything. For example:The standard is to use something like
antlib:net.sf.antcontrib
:However, I like using the URL of the project. That way, if someone wants documentation on Ant-Contrib tasks, they know the URL where the Ant-Contrib project lives.
In all three cases above, I've defined the XML namespace with
ac
. Thus, you have to prefix all Ant-Contrib task names withac:
. You could useantcontrib
or whatever you like. With theac:
namespace, your Ant-contrib tasks will look like this:If you skip the whole namespace thing, you can simply use the Ant-Contrib tasks as documented: