espeed
espeed

Reputation: 4824

How to add a directory containing properties files to an Ant build.xml?

I'm trying to build an "uberjar" with ant, and the project has a config directory with several properties files.

How do I add the config dir to build.xml?

Here's an example of how it's referenced:

static private String CONFIG_DIR = "config/";
static public String CONFIG_FILE = "proj.properties";

File configFile = new File(CONFIG_DIR, CONFIG_FILE);

There are multiple properties files in the config directory. Normally I would just add it to the classpath:

java -classpath bin:lib/*:config some.project.Example

Here's my build.xml target, which isn't quite right:

<target name="uberjar" depends="compile">
  <jar jarfile="${babelnet.jar}">
    <fileset dir="${bin.dir}">
      <include name="**/*.class"/>
    </fileset>
    <zipgroupfileset dir="lib" includes="*.jar"/>
  </jar>
  <copy todir="config">
    <fileset dir="config">
      <include name="**/*.properties"/>
    </fileset>
      </copy>
</target>

Upvotes: 4

Views: 13461

Answers (1)

Christopher Peisert
Christopher Peisert

Reputation: 24194

To include the properties files within the new jar file, you could add another nested <fileset> to the <jar> task.

<target name="uberjar" depends="compile">
  <jar jarfile="${babelnet.jar}">
    <fileset dir="${bin.dir}">
      <include name="**/*.class"/>
    </fileset>
    <zipgroupfileset dir="lib" includes="*.jar"/>
    <fileset dir="${basedir}">
      <include name="config/*.properties"/>
    </fileset>
  </jar>
</target>

Also, see stackoverflow question: How to read a file from a jar file?

Upvotes: 5

Related Questions