How to include file in Jar through Ant at specific location
Question
I've got an ant jar task:
<target name="jar">
<jar destfile="${generated.jars.dir}/hello-${environment}.jar">
<fileset dir="${generated.classes.dir}"/>
<fileset dir="${environment.dir}/${environment}" includes="config.xml"/>
</jar>
</target>
How can I force the config.xml file to be pushed to a specific directory in the jar rather than at the root level, say in /database/config.xml or something like that...
PS: The reason for doing this is that I can have a hello-local.jar, hello-dev.jar, hello-qa.jar, etc.
Solution
Use a zipfileset
like this:
<jar destfile="${generated.jars.dir}/hello-${environment}.jar">
<fileset dir="${generated.classes.dir}"/>
<zipfileset dir="${environment.dir}/${environment}"
includes="config.xml"
fullpath="database/config.xml"/>
</jar>
OTHER TIPS
You want zipfileset:
<zipfileset dir="${environment.dir}/${environment}" includes="config.xml" prefix="database"/>
or:
<zipfileset dir="${environment.dir}/${environment}" includes="config.xml" fullpath="database/config.xml"/>
<!-- Generate EJBs -->
<javadoc destdir="${ejb.build.dir}/src" classpathref="ejb.class.path" docletpath="${wl.home}/lib/ejbgen.jar" doclet="weblogic.tools.ejbgen.EJBGen" maxmemory="512m" docletpathref="class.path" failonerror="true" additionalparam="-descriptorDir ${ejb.build.dir}/src/META-INF -wls81 -forceGeneration">
<fileset dir="${ejb.build.dir}/src" includes="**/ejb/*Bean.java,**/ejb/**/*Bean.java, **/ejb/enterprisemanagement/*EJB.java, **/ejb/sitemanagement/*EJB.java, kaas/gateways/rdm/**" excludes="**/agwmgmt/*.java,**/dstprofilemgmt/*.java, **/KaASBaseSessionBean.java,**/com/hns/iag/kaas/rdm/**">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow