Newbie help with creating a launcher script for my java app


(Robert Leach) #1

Hi,

I have a java app that I package with gradle. Another guy on our team started the gradle script and I’ve been editing it to add some bundling/packaging features. (Note, gradle is the first packaging software I’ve ever used.) I ended up using the setupBuilder plugin in order to create an msi package for windows. It works fairly well. I used desktopStarter to create an alias in the windows start menu that has the app icon and it works. The alias is just set directly to the jar file.

However, I’d like to be able to use a pair of vbs/bat scripts to launch the jar so that I can set specific flags in the script for the java executable (and tell users how to edit it if they need to). I managed to figure out how to get gradle to generate these scripts, and they work!.. if I manually drag them from build/tmp/msi into C:\Program Files\MyApp.

I don’t know how to get gradle to wrap the scripts up into the msi that setupBuilder creates and copy them to the correct location (i.e. C:\Program Files\MyApp) when the msi’s setup wizard installs the app.

I’ve been googling and reading the gradle and setupBuilder documentation. That’s how I was able to get this far, but this last bit seems elusive to me. I’ve been trying to look for some variable or method or something to tell setupBuilder that these 2 script files need to go into the “installation directory” (C:\Program Files\MyApp) when the msi is run. I just can’t seem to figure it out. Any help would be appreciated.

Here’s my latest version of the msi task where I create the scripts:

msi {
  def jarfile = 'treeview3' + '-all-' + getVersionName() + '.jar'
  setupBuilder.desktopStarter {
    displayName = 'TreeView3'
    executable = 'TreeView3.vbs'
  }
  doLast {
      //From https://stackoverflowcom/questions/38275583/
      from files(new File("$projectDir/build/tmp/msi/TreeView3.bat").text = """
@echo off\r
"%JAVA_HOME%\\bin\\java.exe" -Xmx4g -jar "${jarfile}"
"""
        ,
        //From https://superuser.com/questions/233348/
        new File("$projectDir/build/tmp/msi/TreeView3.vbs").text = """
Set WshShell = CreateObject("WScript.Shell")\r
WshShell.Run chr(34) & "TreeView3.bat" & chr(34), 0\r
Set WshShell = Nothing
"""
      )
      into "${projectDir}"
  }
}

Thanks,
Rob