Home arrow static arrow Java Programming [Archive] - updating a jar file
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - updating a jar file
This topic has 10 replies on 1 page.

Posts:97
Registered: 5/26/04
updating a jar file  
Aug 6, 2004 12:24 PM



 
I am using the following ant file in eclipse to build jar files when I ask the project to be built

<project name="atg" default="create-jar">    <target name="create-jar">        <jar jarfile="${jarlocation}/classesDAS.jar">            <fileset dir="WebContent/WEB-INF/classes" includes="**/*.class"/>            <fileset dir="WebContent/WEB-INF/classes" includes="**/*.properties"/>        </jar>    </target></project>


Is there a possibility that I modify this file to rather update jar files rather than creating new ones??????
 

Posts:14,142
Registered: 99-04-02
Re: updating a jar file  
Aug 6, 2004 12:31 PM (reply 1 of 10)



 
In theory, an application could append a Jar/Zip file... but I'm not sure why it matters in your case. It's still going to (in theory) end up with the same Jar file. What's the problem?
 

Posts:3,258
Registered: 00-08-28
Re: updating a jar file  
Aug 6, 2004 12:40 PM (reply 2 of 10)



 
In theory, an application could append a Jar/Zip
file... but I'm not sure why it matters in your case.
It's still going to (in theory) end up with the same
Jar file. What's the problem?

What I understand from the OP is that she wants to update a jar file rather than create a new one. In simple words

rather than jar cvf .......

she wants to do

jsr uvf and change only the files she wants to be changed, rather than repackaging the whole jar file. But unfortunately I am not an ant expert so I dont think I would be able to help much in here.
 

Posts:7,258
Registered: 1/31/02
Re: updating a jar file  
Aug 6, 2004 12:45 PM (reply 3 of 10)



 
I've not tried it, but there is an "update" attribute for the jar ant task.

update indicates whether to update or overwrite the destination file if it already exists. Default is "false".

Try saying

<jar jarfile="${jarlocation}/classesDAS.jar" update="true">
<fileset dir="WebContent/WEB-INF/classes" includes="*/.class"/>
<fileset dir="WebContent/WEB-INF/classes" includes="*/.properties"/>
</jar>


Good Luck

Lee
 

Posts:14,142
Registered: 99-04-02
Re: updating a jar file  
Aug 6, 2004 12:47 PM (reply 4 of 10)



 
Well, I'm not sure I see a realistic point to doing that. First, if it's with an ant script... read the ant documentation on the jar command and see what it says.

The jar application (jar.exe) does have an update option...

jar -uvf [jar-file] [-C dir] files ...

So presumably ant could simply do an update if it has support for it. Or it could potentially do an update automatically to update only new files when the jar already exists.
 

Posts:3,258
Registered: 00-08-28
Re: updating a jar file  
Aug 6, 2004 12:59 PM (reply 5 of 10)



 
I've not tried it, but there is an "update" attribute
for the jar ant task.

update indicates whether to update or overwrite the
destination file if it already exists. Default is
"false".

Try saying

<jar jarfile="${jarlocation}/classesDAS.jar"
update="true">
<fileset dir="WebContent/WEB-INF/classes"
includes="*/.class"/>
<fileset dir="WebContent/WEB-INF/classes"
includes="*/.properties"/>
</jar>


Good Luck

Lee


I tested this on my machine seems that it works. Either its the update flag or that ant always updates the jar files. In either case hopefully that answers the OP's question. %-)

 

Posts:14,142
Registered: 99-04-02
Re: updating a jar file  
Aug 6, 2004 1:03 PM (reply 6 of 10)



 
Something did occur to me.... If you use update, then presumably Ant works by taking newer/modified files that have timestamps after the modified time of the Jar... IF you were to move things around to other packages, or directories for non-class files, in your development process, then you could end up with duplicate items in different locations in the Jar, which could lead to hard to find bugs later if you forgot to update the paths elsewhere, or end up updating the wrong files. So IMO, it's safer all around to just let it create a new Jar so that it's always clean.
 

Posts:97
Registered: 5/26/04
Re: updating a jar file  
Aug 6, 2004 1:19 PM (reply 7 of 10)



 
Something did occur to me.... If you use update, then
presumably Ant works by taking newer/modified files
that have timestamps after the modified time of the
Jar... IF you were to move things around to other
packages, or directories for non-class files, in your
development process, then you could end up with
duplicate items in different locations in the Jar,
which could lead to hard to find bugs later if you
forgot to update the paths elsewhere, or end up
updating the wrong files. So IMO, it's safer all
around to just let it create a new Jar so that it's
always clean.

Thanx all of you for taking out some time to advise me. I really appreciate that. The reason I am more interested in update is because of the situation I am trapped in. We are using a third party API to talk to the oracle database. Though I personally would prefer using JDBC myself but here I have no choice as its a decision made at much higher levels. Now there are advantages with this API that it maintains a cache and you donot have to do SQL queries all the time, but I was having problem since a few days as it would not always provide me with the right results. Since I was the one assigned to look into it I decided to decompile some of the classes and put them into a project in WSAD/Eclipse. Now there are thousands of classes in this jar file and I donot want to decompile all of them and add them to the project what I was wondering was to add this ant script to the project file add some debug statements and hopfully it would change only the files I want it to rather than creating a new jar file with just 10 files rather than all of them. This was the background wiki/./of my question. So what do u suggest now. I donot want to do jar -uvf after moving class files everytime I compile thats why I wanted to use ant.
 

Posts:14,142
Registered: 99-04-02
Re: updating a jar file  
Aug 6, 2004 1:50 PM (reply 8 of 10)



 
Why are you not using a separate Jar with these library classes in them and putting the Jar into the classpath?

If you are modifiying certain classes in that library for whatever reason... you put only the ones you changed into a package directory structure and let Ant Jar those classes in your own Jar... then you have the original library Jar and put both in your classpath, but have yours first. Java will take the classes out of the first Jar it finds along the classpath.

Or if you need them all in one Jar for some reason... You can unpack everything into a directory and have Ant Jar that stuff with your own classes, which presumably you could have Ant compile them into a "build" directory. Then Ant Jars the build directory and the other library directory.

That make sense?
 

Posts:3,258
Registered: 00-08-28
Re: updating a jar file  
Aug 6, 2004 2:37 PM (reply 9 of 10)



 
Why are you not using a separate Jar with these
library classes in them and putting the Jar into the
classpath?

If you are modifiying certain classes in that library
for whatever reason... you put only the ones you
changed into a package directory structure and let Ant
Jar those classes in your own Jar... then you have the
original library Jar and put both in your classpath,
but have yours first. Java will take the classes out
of the first Jar it finds along the classpath.

Or if you need them all in one Jar for some reason...
You can unpack everything into a directory and have
Ant Jar that stuff with your own classes, which
presumably you could have Ant compile them into a
"build" directory. Then Ant Jars the build directory
and the other library directory.

That make sense?

After reading through your Cindy's statement I feel that bsampieri's statement is obviously the right one and I would have done the same thing as well. But keep in mind that in case its a web based application change the CLASSPATH is the server>environment settings as well only the Java Build Path would not do.

 

Posts:14,142
Registered: 99-04-02
Re: updating a jar file  
Aug 9, 2004 7:00 AM (reply 10 of 10)



 
ah... yes.. good point.. IF it's a web based app, then I guess it's best to just extract the classes you need to include and let Ant put them in a single Jar with your other app, as you can't necessarily guarantee Jar file load order.
 
This topic has 10 replies on 1 page.