I have a scenario where I’m trying to reuse the same build.xml file across multiple projects. In each case, the finaly target is a dist that JARs everything up. The only difference is that some of the projects have a src/main/java/META-INF/* directory, and others don’t (and just have a src/main/java/* directory).
I want to use the Ant-Contrib <if/> task to optionally define a META-INF/ directory if the build sees a src/main/java/META-INF/* directory available. So something like this:
<jar jarfile="myapp.jar">
<if>
<available file="src/main/java/META-INF" />
<then>
<!--
Copy everything from src/main/java/META-INF into
the JAR's META-INF directory.
But how?!?
-->
<echo message="I'm trying to copy META-INF!" />
</then>
</if>
</jar>
But I am choking on two things here:
- When I run this target, I get a build exception stating that I can’t nest an
<if/>inside the<jar/>task; and - I’m not sure how to configure the
<jar/>task to create aMETA-INFdirectory at the root of the classpath, and copy all of thesrc/main/java/META-INFcontents into it.
Any thoughts? Thanks in advance.
It sounds like you want to take advantage of a more modular build configuration. How about having two targets:
Then, when you want to build your
META-INF/-containing projects, you just runjar-with-metainf.