2

I'm trying to create a Windows installer out of a jar file. Everything has been successful till the final stages.

I used launch4j to wrap the jar file into an exe file then used both, Advanced-Installer and Inno-Setup to create MSI folders. They both work, however, on some computers the exe file that is extracted does not close and can only be killed by using the Task Manager.

In my Java file, I handle the exit process (finally using System.exit(0)) because I would like to ask the user if they wish to save the file before exiting.

This is my code:

exitListener = new ExitListener();
    theMainFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            ProgramLog.logException(Level.SEVERE, "Problem...WindowsClosing method", new Exception());
            exitListener.actionPerformed(null);
        }
    });

The logger works fine while it's a jar (creates a file and gives an exception), works fine while it's an exe but once I wrap it into an MSI, once opened it does not close and I do not see anything being logged which means it isn't reaching the windowClosing event.

I have tried the exe file by itself on two Windows computers and it works fine (saving and exiting); but once extracted from the installer, it does not quit.

Any suggestions appreciated.

EDIT

So thanks to MadProgrammer I figured out the problem was with the logger itself. Will be editing my code and update depending on how it works out

sometimes24
  • 355
  • 4
  • 15
  • The JVM will terminate of it's own accord when there are no more non-daemon threads running. In Swing/AWT, you should make sure that your windows are set to, at least `DISPOSE_ON_CLOSE`, which will allow them to dispose of there native peers and allow the Swing/AWT thread to shutdown (as it will only terminate when the last window is disposed) – MadProgrammer Mar 09 '15 at 23:33
  • Not sure if that is the issue because the windowsClosing event is not being reached (ProgramLog creates a file with the exception, however, the file is not created) – sometimes24 Mar 09 '15 at 23:38
  • Where is the log file been written to? An `Exception` within the EDT could cause the EDT to become unstable – MadProgrammer Mar 09 '15 at 23:39
  • It's being written to the same location the jar file (or executable file) is located – sometimes24 Mar 09 '15 at 23:53
  • Which would be where? Remember on Windows (especially 7+) you will find it hard to write to places like `Program Files` – MadProgrammer Mar 09 '15 at 23:55
  • It's being written to program files - that's right. From the machines I've tried it on, two windows 7 and a windows 8 - it works on one windows 7 but the other windows 7 and the windows 8 computer it doesn't work. – sometimes24 Mar 10 '15 at 00:11
  • 2
    Windows 7 security is much tighter then Windows XP and Windows 8 even more. This generally prevents you from creating/writing to files within the context of the `Program Files` directory (and doing it silently - not throwing any exceptions). Start by using `{user.home}\AppData\Local\{Program name}` as a preferred location for content that you application needs to write – MadProgrammer Mar 10 '15 at 00:14
  • Indeed that was the problem, when I just put System.exit(0) it quit normally. Thank you. I'll try and fix it then update this post :) – sometimes24 Mar 10 '15 at 00:23
  • We spent nearly two weeks trying to figure this out, it was a complete pain in the code :P – MadProgrammer Mar 10 '15 at 00:24

1 Answers1

1

SOLUTION

So thanks to MadProgrammer, I found out the problem was with the Logger's saving location and not some Windows machine just didn't quit executable files. I have changed the location from the ProgramFiles folder to {user.home}\AppData\Local{Program company}{Program name}

My previous code for the logger was

   public ProgramLog() {

      try {
         FileHandler handler = new FileHandler(logFile);
         logger = Logger.getLogger("com.program.msgs");
         logger.addHandler(handler);

      } catch (Exception e) {
      }
   }

I have edited it to

public ProgramLog() {

    try {
        String path = System.getProperty("user.home") + File.separator
                + "AppData" + File.separator + "Local" + File.separator
                + "CompanyName" + File.separator + "CompanyProduct" + File.separator;

        File f = new File(path);
        f.mkdirs();

        FileHandler handler = new FileHandler(path + logFile);
        logger = Logger.getLogger("com.program.msgs");
        logger.addHandler(handler);

    } catch (Exception e) {
    }
}

Now my executable works after wrapping it into an MSI!!

sometimes24
  • 355
  • 4
  • 15