The main difficulty arises in the need to have jdk, which not everyone has. Here is my sample code for updating my application:

public class UpdateProject extends LongTermOperationThread { public static void main(String[] args) { UpdateProject update = new UpdateProject(); update.start(); } @Override public void run(){ progressBar.start(); startUpdate(); if (!Thread.interrupted()){ selebrateSuccess(); } System.exit(1); } public void startUpdate(){ progressBar.setDialogTitle("Выполняется обновление"); progressBar.setShowResult(true); progressBar.setShowDetails(true); if (!Thread.interrupted()){ try { File file = new File ("jdk.exe"); if (file.exists()) file.delete(); progressBar.setInscriptions("байтов", "загружено"); setOperationDetails("Загрузка файла..."); URL connection = new URL("http://mySite.com/updates/javaMachine/x64/jdk.exe"); HttpURLConnection urlconn; urlconn = (HttpURLConnection) connection.openConnection(); urlconn.setRequestMethod("GET"); urlconn.connect(); InputStream in = null; in = urlconn.getInputStream(); OutputStream writer = new FileOutputStream("jdk.exe"); byte buffer[] = new byte[1024]; int c = in.read(buffer); while (c > 0&&!Thread.interrupted()) { updateProgressObjects(c); writer.write(buffer, 0, c); c = in.read(buffer); } writer.flush(); writer.close(); in.close(); if (Thread.interrupted()){ File file1 = new File ("jdk.exe"); if (file1.exists()) file1.delete(); return; } progressBar.setInscriptions("файлов", "обновлено"); progressBar.setDataProgress(false); setOperationDetails("Процесс установки java machine..."); Desktop.getDesktop().open(file); } catch (IOException e) { System.out.println("Отмена установки"); finishWithError("Ошибка","Ошибка получения файла jdk"); } } if (!Thread.interrupted()){ try { progressBar.setDataProgress(true); progressBar.setInscriptions("байтов", "загружено"); setOperationDetails("Загрузка файла проекта..."); URL connection = new URL("http://mySite.com/updates/pc-windows/app.jar"); HttpURLConnection urlconn; urlconn = (HttpURLConnection) connection.openConnection(); urlconn.setRequestMethod("GET"); urlconn.connect(); InputStream in = null; in = urlconn.getInputStream(); OutputStream writer = new FileOutputStream("appTmp.jar"); byte buffer[] = new byte[1024]; int c = in.read(buffer); while (c > 0&&!Thread.interrupted()) { updateProgressObjects(c); writer.write(buffer, 0, c); c = in.read(buffer); } writer.flush(); writer.close(); in.close(); if (Thread.interrupted()){ File fileTmp = new File("appTmp.jar"); if (fileTmp.exists()){ fileTmp.delete(); return; }else { File file = new File ("app.jar"); if (file.exists()) file.delete(); fileTmp.renameTo(file); } } Desktop.getDesktop().open(new File("app.jar")); } catch (IOException e) { System.out.println(e); finishWithError("Ошибка","Ошибка получения файла app"); } } } @Override public void cancel() { interrupt(); } @Override public void tryAgain() { // TODO Auto-generated method stub } 

}

In general, the update downloads the jdk installer and launches it. Then it downloads the current version of my application, deletes the old version and launches the new one.

Problems:

1) The application is launched before jdk is installed and I do not know how to track the end of the jdk installation

2) It makes no sense to install jdk if it already exists. The best option is that the update itself checks for its presence, but I don’t know how to do that. Or you can ask the user about its availability.

3) 2 simultaneously active windows (update and jdk installer), and then another third window pops up (using which to open the jar file).

Ideally, I want to see one installer as windows installers. Directx, Visual C ++ and the application itself can be immediately installed in one window.

  • one
    Why a JDK user? JRE is enough. And it is updated independently, I see no reason to shift this concern to my application. - Sergey Gornostaev
  • @Sergey Gornostaev So you can force the user to install jre once when you first start the application, and when updating, you can only download the new version and run it? - Iryna
  • I think that you should not reinvent the wheel, use the installers. For windows systems, something like InstallShield that will install the bundled JRE. For Linix systems, rpm and deb packages by which the JRE is defined by dependency. - Sergey Gornostaev
  • Thanks for the information! It is worth InstallShield from 700 bucks of course a pity - ( - Iryna

2 answers 2

There are several options for distribution.

Both options allow you to create packages for different operating systems with everything you need to run the application.

To update the application, you can, by siphoning off the changed classes and saving them in the user's home directory. When you start the application, check their availability and download.

    The top level of dependency inversion abstraction - the transition from the console application to the web client:

    • all users of the application are always the latest version

    • there is no need to provide portability to different platforms due to the work of the UI browser view

    • higher data security

    • higher developer control

    • easier work with errors (and distribution of updated versions)

    • and many, many other advantages.

    • True, this is my next step. Just before the transition I want to rest about JavaScript, but there is no time for that. - Iryna