How to update a jar file for one source file change?

N

NickName

Hi,

I'm new to java, so, I may get terminilogy wrong, bear with me. Here's
the problem. We use a set of tools to perform data extraction from a
repository into XML, then generate HTML for them. For this process,
we've got a BIG jar file that includes thousands of classes. Now,
recently a piece of data that includes section symbol, § was added to
the repository. The current extraction process does not include java
code for automatic translation into HTML encoded code, so, it stops the
HTML generation for this particular piece of data. Process-wise, it's
XML extraction from repository and then HTML (files) generation from
the XML files. As it stands, the second process of HTML generation for
this particular set of data failed.

Given the situation, we added the § to HTML encoded code to a piece of
java code that is being used during the data extraction and HTML
publishing process. However, when we ran a test, results indicate the
process has not translated the symbol, which also means that the
updated java source code was not being used. So, here are some
questions,
the BIG jar file uses some packages, one of which references this
particular java source code.
I've looked jar utility syntax, an inital thought was, to update this
jar file to recompile the updated java source code, however, however,
all the links/references on the web that I've looked at about jar
utility do not indicate how to update a jar file that includes an
updated java file.
Would using the u option alone update all? Then, it does not make
sense for the other thousands of files.

Secondly, how about re-package the package that reference this piece of
java code? Would the re-package recompiled all the referenced java
code/classes? Would I have to do something about the BIG jar file that
references this package or now it's been "updated"?

Many thanks.
 
S

Steve W. Jackson

"NickName said:
Hi,

I'm new to java, so, I may get terminilogy wrong, bear with me. Here's
the problem. We use a set of tools to perform data extraction from a
repository into XML, then generate HTML for them. For this process,
we've got a BIG jar file that includes thousands of classes. Now,
recently a piece of data that includes section symbol, § was added to
the repository. The current extraction process does not include java
code for automatic translation into HTML encoded code, so, it stops the
HTML generation for this particular piece of data. Process-wise, it's
XML extraction from repository and then HTML (files) generation from
the XML files. As it stands, the second process of HTML generation for
this particular set of data failed.

Given the situation, we added the § to HTML encoded code to a piece of
java code that is being used during the data extraction and HTML
publishing process. However, when we ran a test, results indicate the
process has not translated the symbol, which also means that the
updated java source code was not being used. So, here are some
questions,
the BIG jar file uses some packages, one of which references this
particular java source code.
I've looked jar utility syntax, an inital thought was, to update this
jar file to recompile the updated java source code, however, however,
all the links/references on the web that I've looked at about jar
utility do not indicate how to update a jar file that includes an
updated java file.
Would using the u option alone update all? Then, it does not make
sense for the other thousands of files.

Secondly, how about re-package the package that reference this piece of
java code? Would the re-package recompiled all the referenced java
code/classes? Would I have to do something about the BIG jar file that
references this package or now it's been "updated"?

Many thanks.

I'm not sure if I correctly understand your question...but I *think*
you're asking how to update an existing jar file to replace some parts
and perhaps add new ones.

If so, then you can indeed use the -u flag to the jar command, and you
do not need to extract the jar's contents first or anything like that.
I've got an application with a jar where we did just that recently for
one user in need of a rapid bug fix.

To do so, I made the fix and locally compiled the corrected class. Then
I recreated only the portion of the package structure inside the jar
file that contained the modified class file(s). I was able to use a jar
command somewhat like this:

jar -uf myjarfile.jar com

Not all the sub-packages of com were present, as I said. I could well
have included sub-packages that weren't even in the jar before, like
com.newpkg, though it wasn't needed in my case. But the end result was
that the "com" package hierarchy inside my jar file remained intact
except that any class or other files inside my "com" directory ended up
replacing their old counterparts, or got added if they weren't there
before.

= Steve =
 
N

NickName

Steve said:
OP omitted.

I'm not sure if I correctly understand your question...but I *think*
you're asking how to update an existing jar file to replace some parts
and perhaps add new ones.
Remove "and perhaps add new ones.", your understanding is perfect.
If so, then you can indeed use the -u flag to the jar command, and you
do not need to extract the jar's contents first or anything like that.
I've got an application with a jar where we did just that recently for
one user in need of a rapid bug fix.

To do so, I made the fix and locally compiled the corrected class. Then
I recreated only the portion of the package structure inside the jar
file that contained the modified class file(s). I was able to use a jar
command somewhat like this:

jar -uf myjarfile.jar com
Not all the sub-packages of com were present, as I said. I could well
have included sub-packages that weren't even in the jar before, like
com.newpkg, though it wasn't needed in my case. But the end result was
that the "com" package hierarchy inside my jar file remained intact
except that any class or other files inside my "com" directory ended up
replacing their old counterparts, or got added if they weren't there
before.

OK, got you. Great, thanks a bunch. As a side note, this knowledge is
so helpful that I think I'll move some of the backup files under the
same package hierarchy, good practice or real necessity? More likely
the late.
 
A

Andy Dingley

NickName said:
Secondly, how about re-package the package that reference this piece of
java code?

Find yourself a build tool, like Ant, that can easily and automatically
re-build your JAR from scratch. Then do it. If you try to maintain a
product by modifying bits at a time, you'll go barking mad.

A damn good source control system will help too (Subversion is about
the best).

OTOH, JARs are just ZIP files with knobs on. There are any number of
tools, not all of them from the JDK, that can manipulate them for you.
It's not manipulating them that's hard, it's knowing what needs
manipulating.
 
N

NickName

NickName said:
Remove "and perhaps add new ones.", your understanding is perfect.



OK, got you. Great, thanks a bunch. As a side note, this knowledge is
so helpful that I think I'll move some of the backup files under the
same package hierarchy, good practice or real necessity? More likely
the late.

Additional notes:
Good news and bad news. The good news is, the jar update seems
successful, no error msg showing up after running the jar utility for
update per your instruction. The bad news is, the HTML generation for
that particular set of data still failed. And probably I know why, the
previous developer also uses JBuilder (from Borland probably) for this
process, and I noticed that for every java source code, there's an
equivalent of ?.jbx (JBuilder Executable?)
 
W

Wesley Hall

Andy said:
Find yourself a build tool, like Ant, that can easily and automatically
re-build your JAR from scratch. Then do it. If you try to maintain a
product by modifying bits at a time, you'll go barking mad.

+1

I could not agree with this more, trying to manually maintain archives
is a receipe of many wasted hours and IQ points. The fact that you have
mentioned (in a different reply) a problem related to someone else using
different tools in a different way is a big red light.

Check out ant. It looks big and scary when you first look but a few
examples (which are provided in the docs) will demonstrate how
straightforward it is. Then use this build script to build a fresh jar
file from your source files for each change. Once you have it working,
you will be able to build clean and consistent artifacts (in your case a
jar file) every time on every platform.


Once you have the build script working properly, everyone working on the
software should use that script to build the software and not their own
specific tools...
 
A

Andrew Thompson

NickName wrote:
....
Good news and bad news. The good news is, the jar update seems
successful, no error msg showing up after running the jar utility for
update per your instruction. The bad news is, the HTML generation for
that particular set of data still failed. And probably I know why, the
previous developer also uses JBuilder (from Borland probably) for this
process, and I noticed that for every java source code, there's an
equivalent of ?.jbx (JBuilder Executable?)

2 points.
- A search on 'jbx file extension' should lead you
(fairly quickly) to a better definition within a couple
of clicks.
- I agree with Andy Dingley that an Ant build of the jar(s)
is the way to go, here. I have never found a use for jar
updating, but imagine there are any number of 'gotchas'
to consider. A fresh build of the Jar(s) should get around
(most of those) potential problems.

Andrew T.
 
N

NickName

Andrew said:
NickName wrote:
...

2 points.
- A search on 'jbx file extension' should lead you
(fairly quickly) to a better definition within a couple
of clicks.
- I agree with Andy Dingley that an Ant build of the jar(s)
is the way to go, here. I have never found a use for jar
updating, but imagine there are any number of 'gotchas'
to consider. A fresh build of the Jar(s) should get around
(most of those) potential problems.

Andrew T.

Thank you all. Will try to find time to look into ant etc.
recommendation.
 
N

NickName

NickName said:
Thank you all. Will try to find time to look into ant etc.
recommendation.

Hi all,

Let me re-phrase or expand the question a bit. First of all, imho, the
process fails this little symbol is no big deal at all, it's not a show
stopper, not critical at all (Initially I just got rid of this symbol
and let 99.9999999999% of data going through, what is MOST IMPORTANT
would be to use these data, get some value out of it). So, taking the
time and effort to fix it, for one thing, is to accomodate some old
cranky but seemingly more senior guy in the current environment, and
secondly, an opportunity for myself to get into java programming area,
which would be a (skill) addition to my current environment and
possibly future as well;
and thirdly, in case, some more serious problem pops down the road if
we have to keep on using the current process, which is very convoluted
btw.
Hence, the motivation to go a step further. Having said that, noce
againI truly appreciate everyone's ideas/thoughts/advices and thanks
for putting up with my whining.

OK. Good to know that an "update" (even without recompilation error)
may not work.
For fresh build, guess one would use build tool to do it. So, along
this line of thinking, ant is recommended. Any more thoughts as to why
it is better or a beginner like me should use it instead of JBuilder,
which I happen to have a copy?

Many thanks.
 
A

Andrew Thompson

NickName wrote:
....
For fresh build, guess one would use build tool to do it. So, along
this line of thinking, ant is recommended. Any more thoughts as to why
it is better or a beginner like me should use it instead of JBuilder,
which I happen to have a copy?

Doesn't JBuilder run Ant scripts? In any case, I imagine
it should have a button or menu item to creat a Jar.
(The reason people specifically think 'Ant' is because
it is portable between other tools).

Andrew T.
 
N

NickName

Andrew said:
NickName wrote:
...

Doesn't JBuilder run Ant scripts? In any case, I imagine
it should have a button or menu item to creat a Jar.
(The reason people specifically think 'Ant' is because
it is portable between other tools).

Andrew T.

Our critical jar file was generated by JBuilder. Just took a look at
JBuilder (2005), it has ReBuild feature, that would seem to do a fresh
new build, will check with the previous admin/developer before I try
it.

Probably one can run Ant script with JBuilder as well, I'm not there
yet.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top