일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 파이썬
- 자바
- jpa
- write by GPT-4
- spring data jpa
- 웹 크롤링
- 자바네트워크
- kotlin
- 시스템
- flet
- Database
- 역학
- JVM
- android
- 코틀린
- Java
- 소프트웨어공학
- NIO
- 유닉스
- 자바암호
- oracle
- write by chatGPT
- spring integration
- python
- 리눅스
- GPT-4's answer
- chatGPT's answer
- 인프라
- 데이터베이스
- 고전역학
- Today
- Total
기억을 지배하는 기록
Jakarta Common Configuration 본문
설치
DownLoad : http://jakarta.apache.org/commons/configuration/index.html
연관 라이브러리
Common Configuration을 사용하기 위해서는 다음의 연관 라이브러리가 설치 되어 있어야 한다.
1. Jakarta Commons-Beanutils
2. Jakarta Commons-Collections
3. Jakarta Commons-Digester
4. Jakarta Commons-Lang
5. Jakarta Commons-Logging
Sample Program
Sample에서 사용하는 Configuration 파일은 다음과 같이 application.properties, config.xml, user.xml 3개이다. xml 파일을 작성하여 저장할 때는 반드시 UTF-8포맷으로 저장 하여야 한다.
application.properties
# written by PropertiesConfiguration # Tue Dec 27 13:53:27 KST 2005 name = uD6C4uB8E8uAFB8 phone = 02-1234-1234 user.info = ${name} ${phone} |
config.xml
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system/> <properties fileName="application.properties"/> </configuration> |
user.xml
<?xml version="1.0" encoding="UTF-8" ?> <user-definition> <address> <postnumber>123-963</postnumber> <text>서울특별시 서초구 서초동</text> </address> <phone home="123-4567" office="369-8956"/> <name> <first>루꾸</first> <last>후</last> </name> </user-definition> |
MainTest.java
package jakarta.common.config; import java.util.Iterator; import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConfigurationFactory; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.SystemConfiguration; import org.apache.commons.configuration.XMLConfiguration; public class MainTest { public static void main(String[] args) throws Exception { MainTest m = new MainTest(); m.SystemConfigExec(); m.PropertiesExec(); m.PropertiesSave(); m.ConfigFactoryExec(); m.XMLConfigExec(); m.XMLConfigValidationExec(); } public void SystemConfigExec() throws ConfigurationException { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); Iterator keys = config.getKeys(); String key = ""; while(keys.hasNext()) { key = (String)keys.next(); System.out.print(key+" : "); System.out.println(config.getString(key)); } } public void PropertiesExec() throws ConfigurationException { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new PropertiesConfiguration("application.properties")); Iterator keys = config.getKeys(); String key = ""; while(keys.hasNext()) { key = (String)keys.next(); System.out.print(key+" : "); System.out.println(config.getString(key)); } } public void PropertiesSave() throws ConfigurationException { PropertiesConfiguration config = new PropertiesConfiguration("application.properties"); config.setAutoSave(false); config.setProperty("name", "후루꾸"); config.setProperty("phone", "02-1234-1234"); config.save(); Iterator keys = config.getKeys(); String key = ""; while(keys.hasNext()) { key = (String)keys.next(); System.out.print(key+" : "); System.out.println(config.getString(key)); } } public void ConfigFactoryExec() throws ConfigurationException { ConfigurationFactory factory = new ConfigurationFactory("config.xml"); Configuration config = factory.getConfiguration(); Iterator keys = config.getKeys(); String key = ""; while(keys.hasNext()) { key = (String)keys.next(); System.out.print(key+" : "); System.out.println(config.getString(key)); } } public void XMLConfigExec() throws ConfigurationException { XMLConfiguration config = new XMLConfiguration("user.xml"); Iterator keys = config.getKeys(); String key = ""; while(keys.hasNext()) { key = (String)keys.next(); System.out.print(key+" : "); System.out.println(config.getString(key)); } } public void XMLConfigValidationExec() throws ConfigurationException { XMLConfiguration config = new XMLConfiguration(); config.setFileName("user.xml"); config.setValidating(true); config.load(); Iterator keys = config.getKeys(); String key = ""; while(keys.hasNext()) { key = (String)keys.next(); System.out.print(key+" : "); System.out.println(config.getString(key)); } } } |
'오래된글 > Java' 카테고리의 다른 글
Java 네트워크 - 1 (0) | 2018.04.09 |
---|---|
Jakarta Commons Logging (0) | 2018.04.07 |
Introduce Junit4.0 (0) | 2018.04.07 |
HybridJava(HJ) - Beyond the Java Server Pages (0) | 2018.04.07 |
Character and Byte Streams (0) | 2018.04.07 |