[英]How to store paths in configuration file in netbeans?
I have a java project in netBeans that deals with some paths in order to be able to work. 我在netBeans中有一个Java项目,该项目处理一些路径以便能够工作。 It is headache to change the paths every time that you are run it on other machine.
每次在其他计算机上运行路径时更改路径都令人头疼。 Thus, I am wondering if there is a way that help me to come over this issue.
因此,我想知道是否有一种方法可以帮助我解决这个问题。 One suggested to me to use configuration file, but I don't have any idea about how to do it.
一个建议我使用配置文件,但是我不知道如何使用它。 So, kindly could you help me in this, please?
所以,请你帮我一下吗?
You should have the Ant target run in your build.xml
file. 您应该在
build.xml
文件中运行 Ant目标。 In most cases this target contains only one task - the java
task. 在大多数情况下,此目标仅包含一个任务
java
任务。 You can add arg elements to this task. 您可以向该任务添加arg元素。 One of possible types of these elements is
file
. 这些元素的可能类型之一是
file
。 So, your target will look like this: 因此,您的目标将如下所示:
<target name="run" depends="build">
<java classpath="${basedir}" classname="..." fork="yes">
<jvmarg value="-enableassertions"></jvmarg>
<arg file="abc.txt"/>
<arg file="def.txt"/>
</java>
</target>
The Java interpreter will look for files abc.txt
and def.txt
in the base directory of your project. Java解释器将在项目的基本目录中查找文件
abc.txt
和def.txt
。 So, if you run the NetBeans on different machines, then it will be enough to have your data files in this directory. 因此,如果您在不同的计算机上运行NetBeans,则足以将数据文件放在此目录中。 Of course, it's not only possibility - the Ant
build.xml
file is flexible enough to define any location you want. 当然,这不仅是可能的-Ant
build.xml
文件足够灵活以定义所需的任何位置。
As for more info about Ant - http://ant.apache.org/manual/using.html#arg 至于有关Ant的更多信息-http: //ant.apache.org/manual/using.html#arg
ADDITION: 加成:
The filenames, defined via arg
elements in the build.xml
file, will be accessible from Java code via the main
function argument array. 通过
build.xml
文件中的arg
元素定义的文件名可以通过Java函数的main
函数自变量数组访问。 So, the program: 因此,该程序:
public static void main(String ARG[])
{
for (String s: ARG) System.out.println(s);
}
will print: 将打印:
<your absolute project directory>/abc.txt
<your absolute project directory>/def.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.