Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including .properties files while building a project using ant

Tags:

java

build

ant

How can i include .properties, .xml and other resource files while compiling the source code of a project using Ant? Here is my build file:

<?xml version="1.0"?>
<project name="NmzAzzist" basedir="." default="main">
    <property name="src.dir" value="Source/Myproj" />
    <property name="build.dir" value="ReleaseBuild/classes" />
    <property name="jar.dir" value="ReleaseBuild" />

    <path id="master-classpath">
        <fileset dir="lib">
            <include name="*.jar" />
        </fileset>
    </path>

    <target name="clean" description="Clean output directories">
        <delete dir="${build.dir}" />
    </target>

    <target name="build" description="Compile source tree java files">
        <echo>Compiling the source code</echo>
        <mkdir dir="${build.dir}" />
        <javac destdir="${build.dir}" source="1.5" target="1.5" includeantruntime="false">
            <compilerarg value="-Xlint:unchecked" />
            <src path="${src.dir}" />
            <classpath refid="master-classpath" />

        </javac>
    </target>

    <target name="jar" depends="build">
        <mkdir dir="${jar.dir}" />
        <echo>building jar!</echo>

        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${build.dir}">
            <manifest>
                <attribute name="Main-Class" value="com.ushustech.nmsazzist.NMSAzzistApp" />
            </manifest>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true" />
    </target>

    <target name="main" depends="clean,run" />

</project>

Right now my build is only compiling the Java files and producing classes. But I have some property and XML files in various folders (including the source folders), that I would like included in the output directory, that are not getting placed there now. I appreciate any suggestions in accomplishing this task.

like image 394
ѕтƒ Avatar asked Nov 28 '12 08:11

ѕтƒ


People also ask

What is the use of .properties file?

properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.


Video Answer


2 Answers

Copy those resources file before running jar task.

<copy todir="${build.dir}">
    <fileset dir="${src.dir}">
       <exclude name="**/*.java"/>
    </fileset>
</copy>
like image 129
Alex Cheng Avatar answered Oct 26 '22 12:10

Alex Cheng


This would do the trick:

<target name="dist" depends="compile">
    <echo>packaging classes</echo>
    <jar jarfile="${dist.dir}/${project.distname}.jar" basedir="${build.dir}">
      <fileset dir="${src}">
        <include name="*.properties" />
      </fileset>
    </jar>
 </target>
like image 38
aura Avatar answered Oct 26 '22 14:10

aura