5

After building my appplication on Windows using maven (and a little bit of ant) I manually create a Winrar Sfx Installer as follows:

  • Select files, right click and select Add to Archive
  • Use Browse.. to create the archive in the folder above
  • Change Archive Format to Zip
  • Enable Create Archive Format
  • Select Advanced tab
  • Select SFX Options
  • Select Setup tab
  • Enter setup.exe into the Run after Extraction field
  • Select Modes tab
  • Enable Unpack to temporary folder
  • Select text and Icon tab
  • Enter new title
  • Select setup.ico from the same folder that we invoked winrar from
  • Select OK
  • Select OK

But can I automate some/all of this using Windows batch file/ Maven or ant ?

Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • 1
    Have a look there: http://blog.aaronkitchens.com/2014/02/selfextracting-executable-exe-with.html. You will probably end up using something like they used, a mix of ant inside Maven and maybe some maven-exec-plugin. – Tome Jan 28 '15 at 18:38
  • @Tome Hmm, that a good link I did originally try and use 7z but gave up because I couldnt get it working which is why I moved to WinRar, but having moved to WinRar I think its offers a nicer experience for the end user when using Sfx. So now I have to decide whether I can adapt this for WinRar, go back to 7z or just stick with my manual method. – Paul Taylor Jan 28 '15 at 20:46
  • We did something similar a few years ago, and after digging a bit, I got back the working pom. In short (cannot show a lot), we were using two executions of _maven-exec-plugin_, one to create a simple 7z archive (simple 7z command), and another to make this archive self-extractible, using 7zsfx (see here: http://www.7zsfx.info/en/) – Tome Jan 29 '15 at 08:22
  • Just for the sake of other Googler's looking for a WinRAR based solution, check Mofi's suggestion at http://stackoverflow.com/a/24598044/378115 – Julio Nobre Jan 27 '16 at 02:25

1 Answers1

5

Start WinRAR, click in menu Help on Help topics and open tab Contents. You see there the list items:

  • Command line mode
    • Command line syntax
    • Commands
      • "A" - Add to archive
    • Switches
      • ...
  • Self-extracting modules

All information you need to call WinRAR.exe with the right switches to create an SFX can be found in those help articles.

In general there are two possibilities:

  1. You do what you have already done, but before clicking on final OK, you click on button Profiles on tab General and click on list item Save current settings to a new profile. Then you can call WinRAR.exe with switch "-cpMy SFX Profile". Read the help page for this switch.

  2. You specify all options for creating the SFX archives directly on command line.

For the second possibility something like below can be used as template.

"%ProgramFiles%\WinRAR\WinRAR.exe" a -afzip -cfg- -ed -ep1 -k -m5 -r -tl -iicon"Path to icon file\MyApplicationInstall.ico" "-sfx%ProgramFiles%\WinRAR\Zip.sfx" "-zComment file with full path containing SFX options" "Path to Destination Folder\MyApplicationInstall.exe" "Path to files to add to archive\*"

The content for the *.txt comment file for switch -z can be copied from tab Comment of the dialog opened for creating the archive after selecting all the SFX options.

By the way: I would suggest creating RAR self-extracting archives instead of ZIP self-extracting archives as with RAR compression the EXE file with the right switches for best compression using additionally also solid archive options could be much smaller than with ZIP compression.

So you don't need a batch file or any other application to create a WinRAR SFX archive. A simple shortcut file (*.lnk) with the right command line is all you need to create the SFX archive with a double click on this shortcut whenever you want to create a new SFX for your application.

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • Thankyou I used the Save current settings to a new profile method and also enabled Add to context Menu, i then use to load Winrar with the profile settings and I just have to adjust the location the zip file is created each time and then click ok - so I havent completely automated yet much quicker. – Paul Taylor Feb 02 '15 at 13:35
  • 2
    Using Mofi's sugestion, you should use -cfg- switch in order to avoid WinRAR's default settings dependency. Otherwise, WinRAR default settings might override your -zOptions.txt file content. Cheers! – Julio Nobre Jan 26 '16 at 23:35