Vitor Hugo
Vitor Hugo

Reputation: 1126

Updating a Jar in production

I have a Swing/Java application that is being used for clients and has weekly updates. The problem is the setup just lay out the classes and their respective directories and on the update I just update the classes.

I want to do a single jar containing all the classes, but I'm not sure how would I be able to update it...

Also some clients need some updates during the week where only one or two classes would be updated.

What is the right way of doing this ?

Im using Eclipse. EDIT: I know how to create the jar, I just dont know how to dynamically update it.

Upvotes: 1

Views: 989

Answers (2)

Jason C
Jason C

Reputation: 40315

The general way of doing this, even if only small changes were made, would be to repackage your JAR after each update and give that JAR to a user. The user would replace the existing JAR. How you produce your JAR is up to you. Many IDEs support it, you could write a shell script, use existing build systems like ant or maven or even make, whatever. (See edit below)

If your JAR is very large and deployment is cumbersome, you may be able to split your project into smaller subcomponents, each with their own JAR, and only redistribute the ones containing changes. That may or may not be a major refactoring for you, and it might not even be appropriate. For most small or average size projects, this is generally unnecessary.

As for deployment, there are also a zillion ways to make that easier on the user. You could just give them a JAR file. You could use e.g. install4j. You could use Java Web Start (although its kind of clunky). There are others.

Both install4j and JWS support automatically checking for updates. If you choose to support that feature, all you would need to do is update your distribution site, and users would receive updates automatically. That's also up to you.

But a short answer to your question is: If you have all of your classes packaged in a JAR, no matter how many classes change, you'll want to give the entire updated JAR to the user. The benefit that counters this cost is that a JAR is a nice, compressed, self-contained collection of your application/library's source, which makes management and deployment very convenient.

Edit: Responding to your edit where you specify that you are using Eclipse, Josh M gives you instructions in his comment on your answer. To add to his comment, to export a Runnable Jar you'll have to have a Run Configuration set up which, if you've been running your application in Eclipse already, you probably already have. If not you can create one in the Run menu.

Edit 2: Please refer to Thorbjørn Ravn Andersen's answer as well for some good JWS tips.

Upvotes: 2

I would suggest you look into Java WebStart which is designed to do exactly what you need.

You need to first create the finished deployment and then you can look into creating a JNLP file for the deployment, and a way to put all the files to a web server for the user to access. For now just let the user download the whole thing every time you update. When you get more experienced you can look into how you can make incremental updates.

I would strongly recommend including a build number or timestamp in the deployment paths so a jar file is not cached incorrectly in the client by accident.

Upvotes: 3

Related Questions