Question

I am developing a Java desktop application and would like to have an external configuration.xml.
I am developing the application using Netbeans and tried to add the configuration.xml file in the dist directory so that it resides in the application work folder. But when Netbeans executes its clean operation it deletes the dist directory,
Where should I put this configuration.xml file so that it will not be deleted and will exist in the application start-up directory.

Was it helpful?

Solution

You can add this to your build.xml :

<target name="-post-jar">
   <copy todir="${dist.jar.dir}">
       <fileset dir="resources" includes="**"/>
   </copy>        
</target>

You can now put your configuration.xml file in the folder 'resources' (that you need to create) in your project and all files in it will be copied to the dist folder during the build process.

OTHER TIPS

I was able to get this to work, but I couldn't get -post-jar to trigger without explicitly entering it as a dependency in the main build config. This is in Netbeans 7.0.1 for a Rich Client project.

Instead, in build.xml for the Netbeans module where I want to have external resource files (mainly .txt files that the user could potentially edit later), I entered the following:

    <target name="netbeans-extra">
      <echo>Copying resources files to build cluster directory...</echo>
      <mkdir dir="${cluster}/resources"/>
      <copy todir="${cluster}/resources">
        <fileset dir="resources" includes="**"/>
      </copy>
    </target>

Then I create a new directory in my module's top directory (right alongside src, release, build) called 'resources' and place my .txt files in there.

When you do a build on this module, netbeans-extra will get called as a dependency and carry out the creation of a 'resources' folder in the main project build/cluster directory, followed by copying the contents of the project resources directory over there.

Ultimately, when you build a distribution for your project, you'll find the resource directory placed right next to your projects modules directory, making for a nice and neat side by side arrangement.

Correct code...

<target name="-pre-jar">
    <echo>Copying resources files to build directory...</echo>
    <mkdir dir="${dist.jar.dir}/resources"/>
    <copy todir="${dist.jar.dir}/resources">
        <fileset dir="resources" includes="**"/>
    </copy>
</target>

Add this in the main build.xml (not nbproject\build-impl.xml). You may also replace "-pre-jar" with "-post-jar"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top