2.5.2 jar 명령
클래스 파일을 파일 시스템에 저장하는 대신에 JAR 파일이라는 아카이브 파일 한 개 이상에 넣을 수도 있다. JDK에 들어 있는 jar 유틸리티로 이런 아카이브를 만들 수 있다. jar의 명령줄 옵션은 유닉스 tar 프로그램과 비슷하다.
jar --create --verbose --file library.jar com/mycompany/*.class
짧은 옵션을 사용하면 다음과 같다.
jar -c -v -f library.jar com/mycompany/*.class
다음과 같이 tar 형식 옵션을 사용해도 된다.
jar cvf library.jar com/mycompany/*.class
JAR 파일은 보통 라이브러리를 묶는 데 사용한다.
Tip
라이브러리뿐 아니라 프로그램을 묶는 데도 JAR 파일을 사용할 수 있다. 다음 명령으로 JAR 파일을 만든다.
jar -c -f program.jar -e com.mycompany.MainClass com/mycompany/*.class
JAR 파일을 만들면 다음과 같이 프로그램을 실행한다.
java -jar program.jar