|
|
i always paid more attention to programming and never as much attention to how i would distribute by application bundle to others.. i just used to create a excutable jar file, since it was easy to run my app from it and could always re-distribute a newer version if one were to come out.. but now i want to rid myself of this approach..
Instead i plan on making use of http://www.ej-technologies.com/products/install4j/overview.html, quite powerful with all the extra features..
but I still have the problem of making the auto web update, so every time i make a change, I could just upload it to a web server and lay back..
I dont really know how this would be.. but I figure should be something like this:
- Open the app, a running thread opens a web connection to the web server..
- Reads a config file on the server, checks the version of the config file with the version of the app.
- If needed to update, download the appropriate file from the server..
- Then i'm a bit lost..
Also, I've seen some updaters that help if you are using a proxy..
There seems to be no clear examples of this that I can find...
Any help?
|
|
|
|
Well, why not start a new 'process' ? As per my suggestion update process should be independent of main system.
Create one folder where all updates are stored. Put that folder in classpath.
If user updates from the main system then obviously user should restart the system. Or using classloader check if you can load all the classes or jar.
You can use URLConnection's inputstream to download file.
You can keep version file at both client and server side to check.
I don't know what you are upgrading actually.
|
|
|
|
I thought of the creating a service process and running it independent of my application.. but I never tried such a method..
I thought it would be easiler to just run the check every time the application was launched.. if a new version is available, then the user is prompted to download and install the new update..
A very simple example, for example I make changes to a jar library that is linked with my application.. I download that new jar file, and replace it with the old one..
I cannot seem to find any examples online that help with this..
|
|
|
|
1) If you are replacing old jar with new one please make a copy of old jar in temp folder.
2) Also download new jar in temp folder.
3) When you are replacing old jar with new one if replacing fails then show "upgradation error" and again replace back old jar.
4) Also if system is not behaving properly or having compatibility issue. Always Keep rescue wizard which will simply copy older jar.
5) Once copying is completed replace jar. Ask user to restart system. If user says yes then close system
Now this is what my suggestion. Please check if it is useful and matches your requirement.
|
|
|
|
thanks kanad, i think i get most of the concept of this.. but still hoping there was some kind of a framework library i could use to reduce the development time..
oh well.. if any links, let me know..
|
|
|
|
Well,
When you will install package at "user" side it will have 3 submenus in (say) "startup menu" something like this.
Main Application.bat(shortcut)
|
Application ------ Update.bat(shortcut)
|
Uninstall.bat(shortcut)
---------------------------
Now it doesn't matter if you write text based updater.
----------------------------------------------------
This file May help you. It is not "complete" file.
if read=true means read version file from url, don't save file. But if read=false means download and save file from url.
//Downloads file From URL
class Download extends Thread {
String urlString="";
URL url=null;
HttpURLConnection con=null;
InputStream ins=null;
FileOutputStream fout=null;
byte b[];
int c=0;
String text="";
boolean read=false;
StringBuffer stringBuffer=null;
String message="";
boolean downloadComplete=false;
private int size=0,readBytes=0;
Download(boolean read) {
try {
this.read=read;
if(read) {//read Only don't save since version is to read only
this.urlString=getUrlString()+"/"+getVersionFileName();
stringBuffer = new StringBuffer();
} else {// File need to be stored
this.urlString=getUrlString()+"/"+getFileName();
fout = new FileOutputStream("Temp/"+getFileName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
try {
url = new URL(urlString);
con = (HttpURLConnection) url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.connect();
size=con.getContentLength();
progressbar.setMaximum(size);
progressbar.setMinimum(0);
progressbar.setValue(0);
progressbar.setStringPainted(true);
ins=con.getInputStream();
while(c>-1) {
b=new byte[1024];
c=ins.read(b);
if(read) {
stringBuffer.append(new String(b));
} else {
if(c>-1) {
fout.write(b,0,c);
readBytes=readBytes+c;
progressbar.setValue(readBytes);
}
}
}
ins.close();
if(!read) {
fout.close();
cmdUpdate.setEnabled(true);
lblMessage.setText("Updation completed");
updateUserSystem();//Update User System 1) Upgrade version.txt and replace jar
} else {
setVersion(stringBuffer.toString().trim());
}
downloadComplete = true;
} catch (Exception e) {
e.printStackTrace();
}
}
private void updateUserSystem() {
FileOutputStream fout=null;
File F=null;
try {
//Update version file
F = new File(getVersionFileName());
fout = new FileOutputStream(F);
fout.write(version.getBytes());
fout.close();
//Replace old File with new One
File src=null,dest=null;
src= new File("Temp/"+getFileName());
dest = new File(getOlderFileName());
FileInputStream fis = new FileInputStream(src);
FileOutputStream fos = new FileOutputStream(dest);
byte[] buf = new byte[1024];
int i = 0;
while((i=fis.read(buf))!=-1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
} catch (Exception e) {
System.out.println("Error while updating "+e);
}
}
public String getMessage() {
if(read) {
return stringBuffer.toString();
} else {
return "Download Completed..";
}
}
public boolean isDownloadComplete() {
return downloadComplete;
}
}
|
|
<Added>
for example it can be,
update.setUrlString("http://localhost:8080/jsp-examples/Update");
update.setOlderFileName("kat.jar");// File at user side
update.setFileName("kat_new.jar");//File at Server<----Stored at temp folder at client after download
update.setVersionFileName("version.txt");<---This file signature is same at server and client. Only value of version should be changed. If values not match download file.
if(!version.trim().equalsIgnoreCase(userVersion.trim())) {
return true;
} else {
return false;
}
http://localhost:8080/jsp-examples/Update/kat_new.jar <------------download url for update jar file
http://localhost:8080/jsp-examples/Update/version.txt <------------download url for version file
Hope this helps :)
|
|
|
|
hmm.. just saw the code.. let me try it out..
thanks alot kanad..
|
|
|
|
|
|
|