Solved

Including XML files in a jar file when building a project using Ant

Posted on 2013-12-11
3
823 Views
Last Modified: 2013-12-19
I have an Ant script that I use to build a jar file that contains our company's library.  Included in the library are a bunch of Hibernate models and services so I need to include hibernate xml files as part of the build:   Below is the complete script.   My problem is that I can't seem to get Ant to include the XML files as part of the build.   I have to manually open the jar each time and insert the XML files, then save the file.   Any way to do this better?

<?xml version="1.0" encoding="UTF-8"?>
<project name="companyx.makejar" default="makejar" basedir=".">
<target name ="makejar" description="Create a jar for the companyx project">      
<jar jarfile="companyx.jar" includes="**\*.class,*.properties,*.xml" basedir="bin\.">
      <manifest>
                       <attribute name="Main-Class" value="com.companyx.util.DummyMain" />
                         <attribute name="Class-Path" value="dom4j-1.6.1.jar  
                         log4j-1.2.15.jar       
                         ejb3-persistence-1.0.2.GA.jar
                         commons-collections-3.1.jar
                         commons-io-1.3.2.jar
                         javassist-3.4.GA.jar
                         jta-1.1.jar
                         hibernate-emscribedx.cfg.xml      
                         hibernate-emscribedxcode.cfg.xml      
                         commons-lang-2.4.jar
                         commons-logging-1.1.1.jar
                         mysql-connector-java-5.1.24-bin.jar
                         slf4j-api-1.5.2.jar
                         slf4j-log4j12-1.5.2.jar
                         sqljdbc4.jar
                         hibernate-annotations.jar
                         hibernate3.jar
                         cryptoutils.jar
                         log4j-1.2.15.jar
                         httpcore-4.2.1.jar
                         json_simple-1.1.jar
                         httpclient-4.2.1.jar      
                                "/>
             </manifest>
      </jar>
</target>
</project>
0
Comment
Question by:efamilant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Valeri
ID: 39711228
Try this:

<fileset id="resources" dir="${rez}">
        <include name="**/*.properties"/>
        <include name="**/*.gif"/>
        <include name="**/*.jpg"/>
        <include name="**/*.png"/>
        <include name="**/*.xml"/>
    </fileset>
 <target name="jar" depends="compile,revupdate" description="Build jar">
 <jar jarfile="${jarfile}" basedir="${bin}" manifest="Manifest">
 <fileset refid="resources"/>
 </jar>
 </target>
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39711613
A better solution is to have a dedicated resource copying task. That way, the resources can be put in the right place (in the classpath) at runtime, as well as when packaged in an archive. Of course, leaving them permanently in the classpath interferes with clean tasks, so it's better to do it on-demand. e.g.

    <target name="copy-resources">
	<copy todir="${bin.dir}/resources">
	    <fileset dir="${source.dir}">
		    <include name="**/*.properties" />
		    <include name="**/*.xml" />
	    </fileset>
	</copy>
    </target>

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39729766
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question