Java에서 command line parameter들을 parsing 할때 (제가 잘 모르는 건지는 모르겠지만) 스마트한 방법이 없어 고생을 하고 있다가 맘먹고 구글링을 한 끝에 유용한 라이브러리를 알게 되어서 소개도하고 기록도 해 둘겸 글 남깁니다.

Apache에서 만든 Commons CLI인데요, 다음은 홈페이지에 나온 소개글을 발췌한 것입니다.

The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool.

Commons CLI supports different types of options:

  • POSIX like options (ie. tar -zxvf foo.tar.gz)
  • GNU like long options (ie. du --human-readable --max-depth=1)
  • Java like properties (ie. java -Djava.awt.headless=true -Djava.net.useSystemProxies=true Foo)
  • Short options with value attached (ie. gcc -O2 foo.c)
  • long options with single hyphen (ie. ant -projecthelp)


특히, 아래와 같은 help message도 자동으로 만들어 주기 때문에 정말 편하게 사용할 수 있는 것 같습니다.

usage: ls
 -A,--almost-all          do not list implied . and ..
 -a,--all                 do not hide entries starting with .
 -B,--ignore-backups      do not list implied entried ending with ~
 -b,--escape              print octal escapes for nongraphic characters
    --block-size <SIZE>   use SIZE-byte blocks
 -c                       with -lt: sort by, and show, ctime (time of last
                          modification of file status information) with
                          -l:show ctime and sort by name otherwise: sort
                          by ctime
 -C                       list entries by columns


홈페이지에 가면 소스코드매뉴얼, 간단한 가이드까지 보실수 있습니다.

저작자 표시 비영리 변경 금지
Posted by 호아범

트랙백 주소 :: http://www.crazybar.net/trackback/1004 관련글 쓰기

댓글을 달아 주세요

  1. 석우 2010/07/07 14:12  댓글주소  수정/삭제  댓글쓰기

    이런 좋은 프로그램도 공짜로 만들어 주고. 참 고마운 사람이 많아.