sometimes24
sometimes24

Reputation: 365

Executable file not quitting on Windows after wrapping and using installer

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

Upvotes: 2

Views: 420

Answers (1)

sometimes24
sometimes24

Reputation: 365

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!!

Upvotes: 1

Related Questions