Patching Java software
Asked Answered
H

4

5

I'm trying to create a process to patch our current java application so users only need to download the diffs rather than the entire application. I don't think I need to go as low level as a binary diff since most of the jar files are small, so replacing an entire jar file wouldn't be that big of a deal (maybe 5MB at most).

Are there standard tools for determining which files changed and generating a patch for them? I've seen tools like xdelta and vpatch, but I think they work at a binary level.

I basically want to figure out - which files need to be added, replaced or removed. When I run the patch, it will check the current version of the software (from a registry setting) and ensure the patch is for the correct version. If it is, it will then make the necessary changes. It doesn't sound like this would be too difficult to implement on my own, but I was wondering if other people had already done this. I'm using NSIS as my installer if that makes any difference.

Thanks,

Jeff

Hormone answered 17/9, 2010 at 19:50 Comment(0)
B
6

Be careful when doing this--I recommend not doing it at all.

The biggest problem is public static variables. They are actually compiled into the target, not referenced. This means that even if a java file doesn't change, the class must be recompiled or you will still refer to the old value.

You also want to be very careful of changing method signatures--you will get some very subtle bugs if you change a method signature and do not recompile all files that call that method--even if the calling java files don't actually need to change (for instance, change a parameter from an int to a long).

If you decide to go down this path, be ready for some really hard to debug errors (generally no traces or significant indications, just strange behavior like the number received not matching the one sent) on customer site that you cannot duplicate and a lot of pissed off customers.

Edit (too long for comment):

A binary diff of the class files might work but I'd assume that some kind of version number or date gets compiled in and that they'd change a little every compile for no reason but that could be easily tested.

You could take on some strict development practices of not using public final statics (make them private) and not every changing method signatures (deprecate instead) but I'm not convinced that I know all the possible problems, I just know the ones we encountered.

Also binary diffs of the Jar files would be useless, you'd have to diff the classes and re-integrate them into the jars (doesn't sound easy to track)

Can you package your resources separately then minimize your code a bit? Pull out strings (Good for i18n)--I guess I'm just wondering if you could trim the class files enough to always do a full build/ship.

On the other hand, Sun seems to do an okay job of making class files that are completely compatible with the previous JRE release, so they must have guidelines somewhere.

Bolanger answered 17/9, 2010 at 20:8 Comment(1)
insightful thoughts, thanks. What would you recommend? A binary diff instead? Many of my users download from a very low bandwidth connection, so a file of even 50MB could take a couple of hours, so I'm trying to avoid redistributing the whole app.Hormone
M
2

You may want to see if Java WebStart can help you as it is designed to do exactly those things you want to do.

I know that the documentation describes how to create and do incremental updates, but we deploy the whole application as it changes very rarely. It is then an issue of updating the JNLP when ready.

Magnus answered 17/9, 2010 at 20:16 Comment(2)
Interesting. I'll read through the docs, but I'm not sure JNLP is feasible for the environment we're working in.Hormone
You can invoke javaws under the hood, instead of having the user click a link.Overlook
C
1

How is it deployed?

On a local network I just leave everything as .class files in a folder. The startup script uses robocopy or rsync to copy from network share to local. If any .class file is different it is synced down. If not, it doesn't sync.

For non-local network I created my own updater. It downloads a text file of md5sums and compares to local files. If different it pulls file down from http.

Castello answered 18/9, 2010 at 2:1 Comment(0)
B
0

A long time ago the way we solved this was to used Classpath and jar files. Our application was built in a Jar file, and it had a launcher Jar file. The launcher classpath had a patch.jar that was read into the classpath before the main application.jar. This meant that we could update the patch.jar to supersede any classes in the main application.

However, this was a long time ago. You may be better using something like the Java Web Start type of approach, which offers more seamless application updating.

Buhler answered 17/9, 2010 at 20:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.