如何设置java类的Run-configure参数,而不是在eclipse中
我们有java类,用于使用hibernate将数据从xml摄取到数据库, 我们必须以运行配置的形式运行,它需要两个参数如何设置java类的Run-configure参数,而不是在eclipse中,java,eclipse,Java,Eclipse,我们有java类,用于使用hibernate将数据从xml摄取到数据库, 我们必须以运行配置的形式运行,它需要两个参数 1. data/ingest/xml 2. -dtd DTD/sample-dtd.xml 第一个参数是xmlfiles文件夹,第二个参数是dtd,我正在试图找到一种方法,不必在eclipse中设置这些参数,但可能来自.properties文件。当您使用常量时,使用属性文件实际上是一种非常好的方法,并且您不想仅仅因为(比方说)文件的路径更改而重新编译代码 要配置为使用属性,首
1. data/ingest/xml
2. -dtd DTD/sample-dtd.xml
第一个参数是
xml
files文件夹,第二个参数是dtd
,我正在试图找到一种方法,不必在eclipse中设置这些参数,但可能来自.properties
文件。当您使用常量时,使用属性文件实际上是一种非常好的方法,并且您不想仅仅因为(比方说)文件的路径更改而重新编译代码
要配置为使用属性,首先要创建一个属性文件(称之为myApp.properties)
接下来,我们要在应用程序中读取这些属性。您可以使用Java的Properties类来实现这一点
Properties prop = new Properties();
InputStream input = null;
try {
// be sure to give correct path to the properties file
input = new FileInputStream("myApp.properties");
// load a properties file
prop.load(input);
// get the property value by the keys we defined in the properties
String ingestion_path = prop.getProperty("ingestion_xml_path")
...// Now you can use this value ...
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Properties prop = new Properties();
InputStream input = null;
try {
// be sure to give correct path to the properties file
input = new FileInputStream("myApp.properties");
// load a properties file
prop.load(input);
// get the property value by the keys we defined in the properties
String ingestion_path = prop.getProperty("ingestion_xml_path")
...// Now you can use this value ...
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}