Netbeans and external configuration files

倾然丶 夕夏残阳落幕 提交于 2019-11-30 07:09:24

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.

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"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!