You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Pierre8rou <pi...@yahoo.fr> on 2008/08/29 20:41:20 UTC

[Commons Configuration] Setting up a Java application reading a file Properties.

Hello,

I'd like to set up a Java application reading a file Properties.
I think achieve this by filling a class Params and OtherParams classes.
I think using Apache Commons Configuration.
How to write my file Properties?
How to read the file properties to fill  Params class and OtherParams class
?

Thanks,

Pierre8r

Here the class Params :
----------------------
 
package com.test.configuration;
 
public class Params {
	private static String directoryInput;
	private static String directoryOutput;
	private static String fileInput;
	private static String fileOutput;
	private static OtherParams otherParams1, otherParams2, otherParams3;
	
 
	public static void setDirectoryInput(String directoryInput) {
		Params.directoryInput = directoryInput;
	}
 
	public static String getDirectoryInput() {
		return directoryInput;
	}
 
	public static void setDirectoryOutput(String directoryOutput) {
		Params.directoryOutput = directoryOutput;
	}
 
	public static String getDirectoryOutput() {
		return directoryOutput;
	}
 
	public static void setFileInput(String fileInput) {
		Params.fileInput = fileInput;
	}
 
	public static String getFileInput() {
		return fileInput;
	}
 
	public static void setFileOutput(String fileOutput) {
		Params.fileOutput = fileOutput;
	}
 
	public static String getFileOutput() {
		return fileOutput;
	}
 
	public static void setOtherParams1(OtherParams otherParams1) {
		Params.otherParams1 = otherParams1;
	}
 
	public static OtherParams getOtherParams1() {
		return otherParams1;
	}
 
	public static void setOtherParams2(OtherParams otherParams2) {
		Params.otherParams2 = otherParams2;
	}
 
	public static OtherParams getOtherParams2() {
		return otherParams2;
	}
 
	public static void setOtherParams3(OtherParams otherParams3) {
		Params.otherParams3 = otherParams3;
	}
 
	public static OtherParams getOtherParams3() {
		return otherParams3;
	}
 
}
 

Here the class OtherParams :
---------------------------

 
package com.test.configuration;
 
public class OtherParams {
	private static double caract01, caract02, caract03, caract04;
 
	public static void setCaract01(double caract01) {
		OtherParams.caract01 = caract01;
	}
 
	public double getCaract01() {
		return caract01;
	}
 
	public static void setCaract02(double caract02) {
		OtherParams.caract02 = caract02;
	}
 
	public static double getCaract02() {
		return caract02;
	}
 
	public static void setCaract03(double caract03) {
		OtherParams.caract03 = caract03;
	}
 
	public static double getCaract03() {
		return caract03;
	}
 
	public static void setCaract04(double caract04) {
		OtherParams.caract04 = caract04;
	}
 
	public static double getCaract04() {
		return caract04;
	}
 
}
 




-- 
View this message in context: http://www.nabble.com/-Commons-Configuration--Setting-up-a-Java-application-reading-a-file-Properties.-tp19225015p19225015.html
Sent from the Commons - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [Commons Configuration] Setting up a Java application reading a file Properties.

Posted by Oliver Heger <ol...@oliver-heger.de>.
Pierre8rou schrieb:
> Hello,
> 
> I'd like to set up a Java application reading a file Properties.
> I think achieve this by filling a class Params and OtherParams classes.
> I think using Apache Commons Configuration.
> How to write my file Properties?
> How to read the file properties to fill  Params class and OtherParams class
> ?
> 
> Thanks,
> 
> Pierre8r

Basic access to properties files is pretty easy. Have a look at our 
tutorials [1], especially the section about properties [2].

However Commons Configuration won't be able to populate your bean 
classes automatically. You will have to query the properties using the 
Configuration API and pass them to the corresponding setter methods 
manually.

There is the Commons Digester project [3], which is able to parse XML 
files and create and populate corresponding Java beans. But it does not 
support properties files.

Oliver

[1] http://commons.apache.org/configuration/userguide/user_guide.html
[2] 
http://commons.apache.org/configuration/userguide/howto_properties.html#Properties_files
[3] http://commons.apache.org/digester/

> 
> Here the class Params :
> ----------------------
>  
> package com.test.configuration;
>  
> public class Params {
> 	private static String directoryInput;
> 	private static String directoryOutput;
> 	private static String fileInput;
> 	private static String fileOutput;
> 	private static OtherParams otherParams1, otherParams2, otherParams3;
> 	
>  
> 	public static void setDirectoryInput(String directoryInput) {
> 		Params.directoryInput = directoryInput;
> 	}
>  
> 	public static String getDirectoryInput() {
> 		return directoryInput;
> 	}
>  
> 	public static void setDirectoryOutput(String directoryOutput) {
> 		Params.directoryOutput = directoryOutput;
> 	}
>  
> 	public static String getDirectoryOutput() {
> 		return directoryOutput;
> 	}
>  
> 	public static void setFileInput(String fileInput) {
> 		Params.fileInput = fileInput;
> 	}
>  
> 	public static String getFileInput() {
> 		return fileInput;
> 	}
>  
> 	public static void setFileOutput(String fileOutput) {
> 		Params.fileOutput = fileOutput;
> 	}
>  
> 	public static String getFileOutput() {
> 		return fileOutput;
> 	}
>  
> 	public static void setOtherParams1(OtherParams otherParams1) {
> 		Params.otherParams1 = otherParams1;
> 	}
>  
> 	public static OtherParams getOtherParams1() {
> 		return otherParams1;
> 	}
>  
> 	public static void setOtherParams2(OtherParams otherParams2) {
> 		Params.otherParams2 = otherParams2;
> 	}
>  
> 	public static OtherParams getOtherParams2() {
> 		return otherParams2;
> 	}
>  
> 	public static void setOtherParams3(OtherParams otherParams3) {
> 		Params.otherParams3 = otherParams3;
> 	}
>  
> 	public static OtherParams getOtherParams3() {
> 		return otherParams3;
> 	}
>  
> }
>  
> 
> Here the class OtherParams :
> ---------------------------
> 
>  
> package com.test.configuration;
>  
> public class OtherParams {
> 	private static double caract01, caract02, caract03, caract04;
>  
> 	public static void setCaract01(double caract01) {
> 		OtherParams.caract01 = caract01;
> 	}
>  
> 	public double getCaract01() {
> 		return caract01;
> 	}
>  
> 	public static void setCaract02(double caract02) {
> 		OtherParams.caract02 = caract02;
> 	}
>  
> 	public static double getCaract02() {
> 		return caract02;
> 	}
>  
> 	public static void setCaract03(double caract03) {
> 		OtherParams.caract03 = caract03;
> 	}
>  
> 	public static double getCaract03() {
> 		return caract03;
> 	}
>  
> 	public static void setCaract04(double caract04) {
> 		OtherParams.caract04 = caract04;
> 	}
>  
> 	public static double getCaract04() {
> 		return caract04;
> 	}
>  
> }
>  
> 
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org