?
Solved

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

Posted on 2013-12-11
3
Medium Priority
?
867 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

771 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