Netbeans和外部配置文件

时间:2008-11-19 08:06:04

标签: java netbeans external resources

我正在开发一个Java桌面应用程序,并希望有一个外部configuration.xml 我正在使用Netbeans开发应用程序,并尝试在dist目录中添加configuration.xml文件,以便它驻留在应用程序工作文件夹中。但是当Netbeans执行其清理操作时,它会删除dist目录,
我应该在哪里放置这个configuration.xml文件,以便它不会被删除,并且将存在于应用程序启动目录中。

3 个答案:

答案 0 :(得分:12)

您可以将它添加到build.xml:

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

现在,您可以将configuration.xml文件放在项目中的“资源”文件夹中(您需要创建),并在构建过程中将其中的所有文件复制到dist文件夹中。

答案 1 :(得分:1)

我能够让它工作,但我无法在没有明确地将其作为主构建配置中的依赖项输入的情况下触发-post-jar。这是在富客户端项目的Netbeans 7.0.1中。

相反,在Netbeans模块的build.xml中,我希望有外部资源文件(主要是用户以后可能编辑的.txt文件),我输入了以下内容:

    <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>

然后我在我的模块的顶级目录(右边是src,release,build)中创建了一个名为'resources'的新目录,并将我的.txt文件放在那里。

当您对此模块进行构建时,netbeans-extra将作为依赖项调用,并在主项目构建/集群目录中创建“resources”文件夹,然后复制项目资源的内容那边的目录。

最终,当你为你的项目构建一个发行版时,你会发现资源目录就位于你的项目模块目录旁边,这样可以很好地整齐排列。

答案 2 :(得分:1)

纠正代码......

<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>

在main build.xml中添加它(不是nbproject \ build-impl.xml)。您也可以将“-pre-jar”替换为“-post-jar”