Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

618 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