Thursday, December 13, 2012

How to update one or several classes in jar or ear file without doing full build

Sometimes you would like to update just one or several classes in jar or ear archive which is created in some lengthy build process and you do not want to do that full build.

In this example I want to update Yourclass.class class file inside Yourjar.jar jar file and then update it inside Yourear.ear ear file. The class file is already built by your IDE in bin folder in this path:

C:\<path to project>\bin\com\<package path>\Yourclass.class

Copy your jar and ear file to some temporary work folder c:\temp.

First, we will copy the class file with its package path to some temporary folder c:\temp because jar packaging tool will not let you to specify exact target path/folder. Second, we will use jar tool to repackage.


xcopy /Y "C:\<path to project>\bin\com\<package path>\Yourclass.class" c:\temp\com\<package path>\Yourclass.class

jar uf Yourjar.jar com\<package path>\Yourclass.class

jar uf Yourear.ear Yourjar.jar