My situation is somehow interesting. I am trying to use Ant to make a jar file. However, I don’t want every single java file to be compiled. My source code has strcuture something like this:
src
-Contact.Java
-Contact.hbm.xml
-AnotherClass.Java
So, what I want to have in my jar file is as follow:
myjar.jar
-com
--me
---Contact.Class
---Contact.hbm.xml
I don’t want AnotherClass.Class to be there.
Is it possible doint that with Ant ?
The best I come up with is like this:
<target name="condition-hibernate" description="check if there is a java and hbm file then call for compile-hibernate">
<condition property="condition">
<available file="**/*.hbm.xml" />
</condition>
<antcall target="condition-hibernate-part2"/>
</target>
<target name="condition-hibernate-part2" description="check if there is a java and hbm file then call for compile-hibernate">
<javac srcdir="${source.dir}" destdir="${hibernate.dir}">
</target>
I don’t think that I can use Ant to solve my problem as I can’t tell Ant what to compile and what not (I can using exclude and include) but I want to tell Ant compile only files that have an *.hbm.xml file next to them.
I don’t know how to achieve this with Ant’s built-in selectors.
However, if you cannot work around this in any other way you could implement a custom selector that checks if the
.javafile has a corresponding.hbm.xmlfile, e.g.Use it in your
build.xmllike anincludeThis is just the basic idea. (I didn’t test the code.)
The better way would be to avoid such complex dependencies in your build.