You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "David W. Van Couvering" <Da...@Sun.COM> on 2005/11/30 02:14:52 UTC

Adding a class to a jar file programatically

My Google efforts have shown me how to read a jar file, how to create 
and write a new jar file.  I want to add a new entry to an existing jar 
file programatically.  Anybody know how to do this?

Thanks,

David

Re: Adding a class to a jar file programatically

Posted by "David W. Van Couvering" <Da...@Sun.COM>.
Yes, I could do that, it's just that the jar file I want to add to is 
kind of big and I wanted to avoid the overhead.  I guess I need to do 
the copy/rename approach.

David

Bryan Pendleton wrote:
> Oh, I see I misunderstood the question.
> 
> I think in the past I have always made a copy of
> the jar file, added the new entry to the copy, and
> then renamed the files around.
> 
> Sorry for the misunderstanding.
> 
> bryan
> 

Re: Adding a class to a jar file programatically

Posted by Bryan Pendleton <bp...@amberpoint.com>.
Oh, I see I misunderstood the question.

I think in the past I have always made a copy of
the jar file, added the new entry to the copy, and
then renamed the files around.

Sorry for the misunderstanding.

bryan


Re: Adding a class to a jar file programatically

Posted by Bryan Pendleton <bp...@amberpoint.com>.
David W. Van Couvering wrote:
> My Google efforts have shown me how to read a jar file, how to create 
> and write a new jar file.  I want to add a new entry to an existing jar 
> file programatically.  Anybody know how to do this?

Well, jar files are just ZIPs, so you can work with ZipOutputStream
and ZipEntry:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/ZipOutputStream.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/ZipEntry.html

bryan


Re: Adding a class to a jar file programatically

Posted by Rajesh Kartha <ka...@Source-Zone.Org>.
David W. Van Couvering wrote:

> My Google efforts have shown me how to read a jar file, how to create 
> and write a new jar file.  I want to add a new entry to an existing 
> jar file programatically.  Anybody know how to do this?
>
> Thanks,
>
> David

Hi David,

Maybe the following link will be helpful.

http://www.developer.com/java/other/article.php/607931
http://home.mindspring.com/~thornton.rose/articles/ZipJar/part2.html 
(same article)

There is a section on 'Updating' jar file with an example

Regards,
Rajesh