프로그램/java

jar 파일중 특정 파일 (보통 클래스)만 갱신하기

mulderu 2011. 6. 3. 17:07

음 맥에서 포스트를 작성하다 보니 한글이 깨지는 경우가 발생하는군요 
tistory 쪽의 문제는 아닌것 같고, 폰트가 한글이 아니어서 그런듯 합니다.
그래도 한글은 잘 처리 해야 하는데, 아마 tistory 의 엔진이 외국제품인듯 하기고 합니다.
암튼 jar 파일 안에 있는 class 를 바꾸는건 아래의 내용을 참조 하면 됩니다.

암튼 java 개발자는 특히 유지보수를 하다 보면 전에 개발한 내용이 jar 로 되어 있는경우
그 jar 안에 있는 특정 class 만 수정 하려면 아래와 같이 간단하게 처리 된다.

jar uf jarFileName.jar   com.util.changedClass.class 


Updating a JAR File

The Jar tool provides a u option which you can use to update the contents of an existing JAR file by modifying its manifest or by adding files.

The basic command for adding files has this format:

jar uf jar-file input-file(s)

In this command:

  • The u option indicates that you want to update an existing JAR file.
  • The f option indicates that the JAR file to update is specified on the command line.
  • jar-file is the existing JAR file that's to be updated.
  • input-file(s) is a space-deliminated list of one or more files that you want to add to the Jar file.

Any files already in the archive having the same pathname as a file being added will be overwritten.

When creating a new JAR file, you can optionally use the -C option to indicate a change of directory. For more information, see the Creating a JAR File section.

Examples

Recall that TicTacToe.jar has these contents:
META-INF/MANIFEST.MF
TicTacToe.class
audio/
audio/beep.au
audio/ding.au
audio/return.au
audio/yahoo1.au
audio/yahoo2.au
images/
images/cross.gif
images/not.gif

Suppose that you want to add the file images/new.gif to the JAR file. You could accomplish that by issuing this command from the parent directory of the images directory:

jar uf TicTacToe.jar images/new.gif

The revised JAR file would have this table of contents:

META-INF/MANIFEST.MF
TicTacToe.class
audio/
audio/beep.au
audio/ding.au
audio/return.au
audio/yahoo1.au
audio/yahoo2.au
images/
images/cross.gif
images/not.gif
images/new.gif

You can use the -C option to "change directories" during execution of the command. For example:

jar uf TicTacToe.jar -C images new.gif
This command would change to the images directory before adding new.gif to the JAR file. The imagesdirectory would not be included in the pathname of new.gif when it's added to the archive, resulting in a table of contents that looks like this:
META-INF/MANIFEST.MF
TicTacToe.class
audio/
audio/beep.au
audio/ding.au
audio/return.au
audio/yahoo1.au
audio/yahoo2.au
images/
images/cross.gif
images/not.gif
new.gif