Timer's pom.xml: The pom.xml does a few things, but one of the unique tasks is the modification of the NSIS script. Last updated: 10/13/09


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelVersion>4.0.0</modelVersion> <groupId>com.timjohnstondev</groupId> <artifactId>timer</artifactId> <packaging>jar</packaging> <version>1.0.0.0</version> <name>Timer</name> <description></description> <url>http://www.timjohnstondev.com/projects/timer/</url> <inceptionYear>2009</inceptionYear> <licenses> <license> <name>Apache 2</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> </license> </licenses> <organization> <name>Tim Johnston Development, LLC</name> <url>http://www.timjohnstondev.com</url> </organization> <developers> <developer> <id>timjohnston</id> <name>Tim Johnston</name> <email>tim@timjohnstondev.com</email> <timezone>-7</timezone> </developer> </developers> <distributionManagement> <site> <id>timjohnstondev.com</id> <url>file://..\timjohnstondev.com\projects\timer</url> </site> </distributionManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.3.1</version> <scope>test</scope> </dependency> </dependencies> <properties> <longJarFileName>${artifactId}-${version}.${packaging}</longJarFileName> <shortJarFileName>${name}.${packaging}</shortJarFileName> <webSiteDir>../timjohnstondev.com</webSiteDir> <webSiteAppsDir>../timjohnstondev.com/applications</webSiteAppsDir> <installerDir>installer</installerDir> <installerExe>${name} Installer.exe</installerExe> <installCreater>C:\Program Files\NSIS\makensis.exe</installCreater> <installerScript>${name} Installer.nsi</installerScript> <applicationIcon>T-96x96.ico</applicationIcon> <installerIcon>T-96x96-transparent.ico</installerIcon> <uninstallerIcon>arrow-uninstall.ico</uninstallerIcon> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>com.timjohnstondev.timer.TimerApplication</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>cleaner</id> <phase>validate</phase> <configuration> <tasks> <delete file="${webSiteAppsDir}/${shortJarFileName}" /> <delete file="${webSiteAppsDir}/${installerExe}" /> <delete file="${installerDir}/${shortJarFileName}" /> <delete file="${installerDir}/${installerExe}" /> <delete file="${webSiteDir}/${installerScript}" /> <delete file="${webSiteDir}/${name} pom.xml" /> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> <execution> <id>copyCompile</id> <phase>verify</phase> <configuration> <tasks> <copy file="target/${longJarFileName}" tofile="${installerDir}/${shortJarFileName}" /> <replaceregexp file="${installerDir}/${installerScript}" match="!define PROJECT_NAME .*" replace='!define PROJECT_NAME "${name}"' /> <replaceregexp file="${installerDir}/${installerScript}" match="!define VERSION .*" replace='!define VERSION "${version}"' /> <replaceregexp file="${installerDir}/${installerScript}" match="!define COMPANY .*" replace='!define COMPANY "${organization.name}"' /> <replaceregexp file="${installerDir}/${installerScript}" match="!define URL .*" replace='!define URL "${organization.url}"' /> <replaceregexp file="${installerDir}/${installerScript}" match="!define APPLICATION_ICON .*" replace='!define APPLICATION_ICON "${applicationIcon}"' /> <replaceregexp file="${installerDir}/${installerScript}" match="!define INSTALLER_ICON .*" replace='!define INSTALLER_ICON "${installerIcon}"' /> <replaceregexp file="${installerDir}/${installerScript}" match="!define UNINSTALLER_ICON .*" replace='!define UNINSTALLER_ICON "${uninstallerIcon}"' /> <exec executable="${installCreater}"> <arg value="/V1" /> <arg value="${installerDir}/${installerScript}" /> </exec> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> <execution> <id>copyExe</id> <phase>install</phase> <configuration> <tasks> <copy file="target/${longJarFileName}" tofile="${webSiteAppsDir}/${shortJarFileName}" /> <copy file="${installerDir}/${installerExe}" tofile="${webSiteAppsDir}/${installerExe}" /> <copy file="${installerDir}/${installerScript}" tofile="${webSiteDir}/${installerScript}" /> <copy file="pom.xml" tofile="${webSiteDir}/${name} pom.xml" /> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>ant</groupId> <artifactId>ant-nodeps</artifactId> <version>1.6.5</version> </dependency> </dependencies> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <reportSets> <reportSet> <reports> <report>index</report> <report>license</report> <report>project-team</report> <report>summary</report> </reports> </reportSet> </reportSets> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <outputEncoding>UTF-8</outputEncoding> <configLocation>.checkstyle.xml</configLocation> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <configuration> <linkXref>true</linkXref> <sourceEncoding>UTF-8</sourceEncoding> <minimumTokens>100</minimumTokens> <targetJdk>1.6</targetJdk> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <reportSets> <reportSet> <reports> <report>javadoc</report> <!-- <report>test-javadoc</report> --> </reports> </reportSet> </reportSets> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jxr-plugin</artifactId> <reportSets> <reportSet> <reports> <report>jxr</report> <!-- <report>test-jxr</report> --> </reports> </reportSet> </reportSets> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin> </plugins> </reporting> </project>


Timer's NSIS script: The NSIS script is as generic as possible for my use. The pom.xml should make any changes that are needed for a specific application. Last updated: 10/13/09


/* Timer builder with JRE locator */ /* ================================================================= */ /* Includes */ !include Sections.nsh !include MUI2.nsh !include FileFunc.nsh !include WordFunc.nsh /* ================================================================= */ /* General Product Definitions */ !define PROJECT_NAME "Timer" !define VERSION "1.0.0.0" !define COMPANY "Tim Johnston Development, LLC" !define URL "http://www.timjohnstondev.com" !define APPLICATION_ICON "T-96x96.ico" !define INSTALLER_ICON "T-96x96-transparent.ico" !define UNINSTALLER_ICON "arrow-uninstall.ico" !define JAR_FILE "${PROJECT_NAME}.jar" !define EXE_FILE "${PROJECT_NAME}.exe" !define LICENSE_FILE "License.txt" !define PROPERTIES_FILE "${PROJECT_NAME}.properties" !define INSTALLER_FILE "${PROJECT_NAME} Installer.exe" !define REGKEY "SOFTWARE\${PROJECT_NAME}" !define UNINSTALL_REGKEY "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PROJECT_NAME}" !define UNINSTALLER_FILE "Uninstaller.exe" /* ================================================================= */ /* Installer attributes */ Name "${PROJECT_NAME}" InstallDir "$PROGRAMFILES\${PROJECT_NAME}" LicenseData "${LICENSE_FILE}" OutFile "${INSTALLER_FILE}" CRCCheck on InstallDirRegKey HKLM "${REGKEY}" Path /* ================================================================= */ /* Variables */ Var StartMenuGroup Var jre Var javaHome Var jreCurrentVersion Var jreTempInstallFile Var jreDownloadStatus Var jreInstallCompletionCode Var jreComparisonCode /* ================================================================= */ /* Version Tab information for Setup.exe properties */ VIAddVersionKey ProductName "${PROJECT_NAME}" VIAddVersionKey ProductVersion "${VERSION}" VIAddVersionKey CompanyName "${COMPANY}" VIAddVersionKey CompanyWebsite "${URL}" VIAddVersionKey FileVersion "${VERSION}" VIAddVersionKey FileDescription "Application Installer" VIAddVersionKey LegalCopyright "Copyright ${YEAR} ${COMPANY}" VIProductVersion "${VERSION}" /* ================================================================= */ /* Modern Interface Configuration */ !define MUI_ICON "${INSTALLER_ICON}" !define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM !define MUI_STARTMENUPAGE_REGISTRY_KEY "${REGKEY}" !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuGroup !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${PROJECT_NAME}" !define MUI_UNICON "${UNINSTALLER_ICON}" !define MUI_UNFINISHPAGE_NOAUTOCLOSE /* ================================================================= */ /* Modern Interface Pages */ !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "${LICENSE_FILE}" !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES !insertmacro MUI_LANGUAGE English # Installer sections Section -Main SEC0000 Call GetJRE SetOutPath $INSTDIR SetOverwrite on File ${JAR_FILE} File ${EXE_FILE} File ${APPLICATION_ICON} CreateDirectory "$SMPROGRAMS\$StartMenuGroup" CreateShortCut "$SMPROGRAMS\$StartMenuGroup\${PROJECT_NAME}.lnk" "$INSTDIR\${EXE_FILE}" "" "$INSTDIR\${APPLICATION_ICON}" ; CreateShortCut "$SMPROGRAMS\TaskTracker\ TaskTracker Help.lnk" "$INSTDIR\TaskTrackrl" "" "$INSTDIR\help.ico" WriteRegStr HKLM "${REGKEY}\Components" Main 1 SectionEnd Section "Desktop Shortcut" SEC0001 CreateShortcut "$DESKTOP\${PROJECT_NAME}.lnk" "$INSTDIR\${EXE_FILE}" "" "$INSTDIR\${APPLICATION_ICON}" WriteRegStr HKLM "${REGKEY}\Components" "Desktop Shortcut" 1 SectionEnd Section "Quick Launch Shortcut" SEC0002 CreateShortcut "$QUICKLAUNCH\${PROJECT_NAME}.lnk" "$INSTDIR\${EXE_FILE}" "" "$INSTDIR\${APPLICATION_ICON}" WriteRegStr HKLM "${REGKEY}\Components" "Quick Launch Shortcut" 1 SectionEnd Section -post SEC0003 WriteRegStr HKLM "${REGKEY}" Path $INSTDIR SetOutPath $INSTDIR WriteUninstaller "$INSTDIR\${UNINSTALLER_FILE}" !insertmacro MUI_STARTMENU_WRITE_BEGIN Application SetOutPath "$SMPROGRAMS\$StartMenuGroup" CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall ${PROJECT_NAME}.lnk" "$INSTDIR\${UNINSTALLER_FILE}" !insertmacro MUI_STARTMENU_WRITE_END WriteRegStr HKLM "${UNINSTALL_REGKEY}" DisplayName "${PROJECT_NAME}" WriteRegStr HKLM "${UNINSTALL_REGKEY}" DisplayVersion "${VERSION}" WriteRegStr HKLM "${UNINSTALL_REGKEY}" Publisher "${COMPANY}" WriteRegStr HKLM "${UNINSTALL_REGKEY}" URLInfoAbout "${URL}" WriteRegStr HKLM "${UNINSTALL_REGKEY}" DisplayIcon "$INSTDIR\${UNINSTALLER_FILE}" WriteRegStr HKLM "${UNINSTALL_REGKEY}" UninstallString "$INSTDIR\${UNINSTALLER_FILE}" WriteRegDWORD HKLM "${UNINSTALL_REGKEY}" NoModify 1 WriteRegDWORD HKLM "${UNINSTALL_REGKEY}" NoRepair 1 SectionEnd # Macro for selecting uninstaller sections !macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID Push $R0 ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}" StrCmp $R0 1 0 next${UNSECTION_ID} !insertmacro SelectSection "${UNSECTION_ID}" GoTo done${UNSECTION_ID} next${UNSECTION_ID}: !insertmacro UnselectSection "${UNSECTION_ID}" done${UNSECTION_ID}: Pop $R0 !macroend # Uninstaller sections Section /o "-un.Quick Launch Shortcut" UNSEC0002 Delete /REBOOTOK "$QUICKLAUNCH\${PROJECT_NAME}.lnk" DeleteRegValue HKLM "${REGKEY}\Components" "Quick Launch Shortcut" SectionEnd Section /o "-un.Desktop Shortcut" UNSEC0001 Delete /REBOOTOK "$DESKTOP\${PROJECT_NAME}.lnk" DeleteRegValue HKLM "${REGKEY}\Components" "Desktop Shortcut" SectionEnd Section /o -un.Main UNSEC0000 Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\${PROJECT_NAME}.lnk" Delete /REBOOTOK "$INSTDIR\${APPLICATION_ICON}" Delete /REBOOTOK "$INSTDIR\${EXE_FILE}" Delete /REBOOTOK "$INSTDIR\${JAR_FILE}" Delete /REBOOTOK "$INSTDIR\${PROPERTIES_FILE}" DeleteRegValue HKLM "${REGKEY}\Components" Main SectionEnd Section -un.post UNSEC0003 DeleteRegKey HKLM "${UNINSTALL_REGKEY}" Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall ${PROJECT_NAME}.lnk" Delete /REBOOTOK "$INSTDIR\${UNINSTALLER_FILE}" DeleteRegValue HKLM "${REGKEY}" StartMenuGroup DeleteRegValue HKLM "${REGKEY}" Path DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components" DeleteRegKey /IfEmpty HKLM "${REGKEY}" RmDir /REBOOTOK "$SMPROGRAMS\$StartMenuGroup" RmDir /REBOOTOK "$INSTDIR" Push $R0 StrCpy $R0 $StartMenuGroup 1 StrCmp $R0 ">" no_smgroup no_smgroup: Pop $R0 SectionEnd # Installer functions Function .onInit InitPluginsDir FunctionEnd # Uninstaller functions Function un.onInit SetAutoClose true ReadRegStr "$INSTDIR" HKLM "${REGKEY}" Path !insertmacro MUI_STARTMENU_GETFOLDER Application "$StartMenuGroup" !insertmacro SELECT_UNSECTION Main ${UNSEC0000} !insertmacro SELECT_UNSECTION "Desktop Shortcut" ${UNSEC0001} !insertmacro SELECT_UNSECTION "Quick Launch Shortcut" ${UNSEC0002} FunctionEnd # Section Descriptions !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SEC0001} "Creates a desktop shortcut for this application." !insertmacro MUI_DESCRIPTION_TEXT ${SEC0002} "Creates a Quick Launch shortcut for this application." !insertmacro MUI_FUNCTION_DESCRIPTION_END /* ================================================================= */ /* Java and JRE Definitions */ !define JRE_VERSION "1.6" !define JRE_INSTALL_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=31620&/jre-6u14-windows-i586-s.exe" !define JRE_DOWNLOAD_URL "http://www.java.com" !define JAVA_EXE "javaw.exe" /* ================================================================= */ /* Returns the full path of a valid javaw.exe; looks in: 1 - the $SYSDIR 2 - JAVA_HOME environment variable 3 - the registry 4 - tries to download the JRE, then rechecks $SYSDIR and registry 5 - hopes it is in current dir or PATH */ Function GetJRE ; 1) Check in $SYSDIR ClearErrors StrCpy $jre "$SYSDIR\${JAVA_EXE}" IfErrors CheckJavaHome IfFileExists $jre 0 CheckJavaHome Call CheckJREVersion IfErrors CheckJavaHome JreFound ; 2) Check for JAVA_HOME CheckJavaHome: ClearErrors ReadEnvStr $javaHome "JAVA_HOME" StrCpy $jre "$javaHome\bin\${JAVA_EXE}" IfErrors CheckRegistry IfFileExists $jre 0 CheckRegistry Call CheckJREVersion IfErrors CheckRegistry JreFound ; 3) Check for registry CheckRegistry: ClearErrors ReadRegStr $jreCurrentVersion HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" ReadRegStr $javaHome HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$jreCurrentVersion" "JavaHome" StrCpy $jre "$javaHome\bin\${JAVA_EXE}" IfErrors DownloadJRE IfFileExists $jre 0 DownloadJRE Call CheckJREVersion IfErrors DownloadJRE JreFound ; 4) Download and check installation DownloadJRE: MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON1 "${PROJECT_NAME} uses Java Runtime Environment (JRE) \ ${JRE_VERSION}. To complete the installation, $\r$\nthe JRE will be downloaded and installed. This may take \ several minutes. $\r$\n $\r$\nDo you want to continue?" IDYES true IDNO false false: Goto GoodLuck true: Goto next next: StrCpy $jreTempInstallFile "$TEMP\Java Runtime Environment.exe" nsisdl::download /TIMEOUT=30000 ${JRE_INSTALL_URL} $jreTempInstallFile Pop $jreDownloadStatus ;Get the return value StrCmp $jreDownloadStatus "success" +3 MessageBox MB_ICONSTOP "Download failed: $jreDownloadStatus $\r$\n $\r$\nPlease try the install again." Abort ExecWait '$jreTempInstallFile /s /v\"/qn REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0\"' $jreInstallCompletionCode Delete $jreTempInstallFile ; 4.1) Check in $SYSDIR again ClearErrors StrCpy $jre "$SYSDIR\${JAVA_EXE}" IfErrors CheckRegistry2 IfFileExists $jre 0 CheckRegistry2 Call CheckJREVersion IfErrors CheckRegistry2 JreFound ; 4.2) Check for registry again CheckRegistry2: ClearErrors ReadRegStr $jreCurrentVersion HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" ReadRegStr $javaHome HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$jreCurrentVersion" "JavaHome" StrCpy $jre "$javaHome\bin\${JAVA_EXE}" IfFileExists $jre 0 GoodLuck Call CheckJREVersion IfErrors GoodLuck JreFound ; 5) wishing you good luck GoodLuck: ClearErrors StrCpy $jre "${JAVA_EXE}" IfErrors +4 IfFileExists $jre 0 +3 Call CheckJREVersion IfErrors 0 JreFound MessageBox MB_ICONSTOP "Cannot find appropriate Java Runtime Environment." Abort JreFound: SetOutPath $INSTDIR FileOpen $9 "${PROJECT_NAME}.properties" w FileWrite $9 "JREversion = ${JRE_VERSION}$\r$\n" FileWrite $9 "RunType = 0$\r$\n" FileWrite $9 "PathJRE = $\"$jre$\"$\r$\n" FileWrite $9 "URL_InstallJRE = ${JRE_DOWNLOAD_URL}$\r$\n" FileWrite $9 "Display_BoxInstall = 1$\r$\n" FileClose $9 FunctionEnd /* ================================================================= */ /* Compare the installed version to the required version. */ Function CheckJREVersion ; Get the file version of javaw.exe ${GetFileVersion} $jre $jreCurrentVersion ${VersionCompare} ${JRE_VERSION} $jreCurrentVersion $jreComparisonCode ; Check whether $jreComparisonCode != "1" ClearErrors StrCmp $jreComparisonCode "2" CheckDone 0 SetErrors CheckDone: FunctionEnd