Apache Commons Library
Java를 통해 개발을 하면서 유지보수성과 재사용성을 높이는것은 개발 효율성을 극대화 시킬수 있는 중요한 요소이다.
때문에 여러 module을 구현하면서 공통적으로 사용되는 기능에 대해서 일일이 직접 구현하기보다 누군가 구현해놓은 것을 필요에 맞게 사용하는 것이 중요하다.
또한 대중적으로 널리 사용되는 라이브러리는 많은 사람들이 사용함으로인해 검증된 코드일 가능성이 높다.
Apache 재단의 Commons 라이브러리
Apache Commons – Apache Commons
Welcome to Apache Commons Apache Commons is an Apache project focused on all aspects of reusable Java components. The Apache Commons project is composed of three parts: The Commons Proper - A repository of reusable Java components. The Commons Sandbox - A
commons.apache.org
아파치 재단에서 관리하는 Commons는 재사용 가능한 Java 관련 공통 컴포넌트를 모아놓은 프로젝트이다.
매우 방대한 프로젝트들이 존재하는데 크게 3가지로 나눌수 있다.
- Commons Proper
아파치 커뮤니티 안에서 서로 재사용 가능하도록 개발 및 활용이 가능한 프로젝트들의 모임이다. 이 프로젝트들은 외부 라이브러리의 사용이 거의 없어 아파치 소프트웨어 외부의 변경에 영향을 받지 않고 내부적으로 안정적으로 개발할 수 있도록 되어있다. 약 40개의 항목이 있다.
BCEL | Byte Code Engineering Library - analyze, create, and manipulate Java class files | 6.9.0 | 2024-04-27 | |
BeanUtils | Easy-to-use wrappers around the Java reflection and introspection APIs. | 1.9.4 | 2019-08-13 | |
BSF | Bean Scripting Framework - interface to scripting languages, including JSR-223 | 3.1 | 2010-06-24 | |
CLI | Command Line arguments parser. | 1.7.0 | 2024-04-18 | |
Codec | General encoding/decoding algorithms (for example phonetic, base64, URL). | 1.17.0 | 2024-04-27 | |
Collections | Extends or augments the Java Collections Framework. | 4.5.0-M1 | 2024-04-02 | |
Compress | Defines an API for working with tar, zip and bzip2 files. | 1.26.1 | 2024-03-08 | |
Configuration | Reading of configuration/preferences files in various formats. | 2.10.1 | 2024-03-20 | |
Crypto | A cryptographic library optimized with AES-NI wrapping Openssl or JCE algorithm implementations. | 1.2.0 | 2023-01-23 | |
CSV | Component for reading and writing comma separated value files. | 1.11.0 | 2024-05-02 | |
Daemon | Alternative invocation mechanism for unix-daemon-like java code. | 1.3.4 | 2023-05-12 | |
DBCP | Database connection pooling services. | 2.12.0 | 2024-03-04 | |
DbUtils | JDBC helper library. | 1.8.1 | 2023-09-14 | |
Digester | XML-to-Java-object mapping utility. | 3.2 | 2011-12-13 | |
Library for sending e-mail from Java. | 1.6.0 | 2023-12-22 | ||
Exec | API for dealing with external process execution and environment management in Java. | 1.4.0 | 2024-01-05 | |
FileUpload | File upload capability for your servlets and web applications. | 1.5 | 2023-12-27 | |
FileUpload2 | File upload capability for your servlets and web applications. | 2.0.0-M1 | 2023-07-19 | |
Geometry | Space and coordinates. | 1.0 | 2021-08-21 | |
Imaging (previously called Sanselan) | A pure-Java image library. | 1.0.0-alpha5 | 2024-04-18 | |
IO | Collection of I/O utilities. | 2.16.1 | 2024-04-08 | |
JCI | Java Compiler Interface | 1.1 | 2013-10-14 | |
JCS | Java Caching System | 3.2 | 2023-08-22 | |
Jelly | XML based scripting and processing engine. | 1.0.1 | 2017-09-25 | |
Jexl | Expression language which extends the Expression Language of the JSTL. | 3.3 | 2023-03-27 | |
JXPath | Utilities for manipulating Java Beans using the XPath syntax. | 1.3 | 2008-08-14 | |
Lang | Provides extra functionality for classes in java.lang. | 3.14.0 | 2023-11-21 | |
Logging | Wrapper around a variety of logging API implementations. | 1.3.1 | 2024-03-24 | |
Math | Lightweight, self-contained mathematics and statistics components. | 4.0-beta1 | 2022-12-20 | |
Net | Collection of network utilities and protocol implementations. | 3.10.0 | 2023-10-05 | |
Numbers | Number types (complex, quaternion, fraction) and utilities (arrays, combinatorics). | 1.1 | 2022-11-01 | |
Pool | Generic object pooling component. | 2.12.0 | 2023-09-30 | |
RDF | Common implementation of RDF 1.1 that could be implemented by systems on the JVM. | 0.5.0 | 2017-12-23 | |
RNG | Implementations of random numbers generators. | 1.5 | 2022-10-10 | |
SCXML | An implementation of the State Chart XML specification aimed at creating and maintaining a Java SCXML engine. It is capable of executing a state machine defined using a SCXML document, and abstracts out the environment interfaces. |
0.9 | 2008-12-01 | |
Statistics | Statistics. | 1.0 | 2022-12-05 | |
Text | Apache Commons Text is a library focused on algorithms working on strings. | 1.12.0 | 2024-04-16 | |
Validator | Framework to define validators and validation rules in an xml file. | 1.8.0 | 2023-12-07 | |
VFS | Virtual File System component for treating files, FTP, SMB, ZIP and such like as a single logical file system. | 2.9.0 | 2021-07-21 | |
Weaver | Provides an easy way to enhance (weave) compiled bytecode. | 2.0 | 2018-09-07 |
- Commons Sandbox
Sandbox는 Commons 개발자들에게 소스의 공유 및 협업을 할 수 있는 Subversion 공간을 제공한다. 아직 Proper 단계로 올라가지 못한 단계의 프로젝트들을 모아놓은 공간이다. 소스가 제공되지 않거나 되더라도 snapshot 형태로 제공되며 API의 변경도 미리 공지 없이 바뀔 수 있다.
- Commons Dormant
Commons Dormant는 최근에 거의 활동이 없이 정지된 프로젝트들의 목록이다. 이 컴포넌트들이 필요하다면 직접 빌드해야 할 수도 있으며 더 이상 새 버전이 나오지 않을 가능성도 있다.
Commons의 Configuration 컴포넌트 사용하기
프로그램 개발시 DB,Build등 다양한 환경설정에 관한 정보를 손쉽게 관리하기 위해 별도의 xml이나 properties 파일을 통해 관리한다.
이러한 apache.commons.configuration은 이러한 Configuration에 관한 다양한 기능을 제공하는 컴포넌트이다.
<configuration>
<databases>
<database name="dbName">
<dbDriver></dbDriver>
<dbServer></dbServer>
<dbLogin></dbLogin>
<dbPassword></dbPassword>
<dbMaxActive></dbMaxActive>
<dbMaxIdle></dbMaxIdle>
</database>
</databases>
</configuration>
다음과 같은 xml 설정파일이 있다면, 해당 xml파일에서 database 연결에 관한 환경설정 정보를 명시한뒤,
필요한 곳에서 commons 라이브러리의 Configurations 컴포넌트를 통해 다음과 같이 불러올수있다.
Configurations configurations = new Configurations();
config = configurations.xml("database.xml");
예를들어, 해당 xml 파일의 특정 key의 String 문자열을 가져오고싶다면,
config.getString(key); 를 통해 가져오면 된다.
Configurations 클래스가 제공하는 다양한 메소드들은 공식문서나 구글링을 통해 그때 그때 필요한 메소드를 찾아서 사용만 하면 된다.