views:

517

answers:

2

Hi,

I have an application for which we use IzPack to create the installer. The installer is working fine in its current state, however, I need to add functionality that enables it to check whether an existing version of the software has been installed.

I understand IzPack supports this out of the box using its CheckedHelloPanel, unfortunately that only works for Windows, as it appears to depend on the windows registry.

Is there a way to configure IzPack such that it is able to detect existing installations?

I need to be able to detect whether there is one and merely display a message notifying the user... Bonus points for how to give the user the option to trigger the uninstaller of the existing installation.


  • Assume that the software will only be installed using the new installer
  • IzPack only: please do not suggest alternatives, as we cannot change that now
  • If you suggest using <validator>, please include a code sample of the validator class, because I have considered this, but don't know where to start
A: 

It only works on Windows, because only Windows has a registry. However, in Linux apps traditionally don't have customized unified locations. For example your run scripts would go in a bin folder, your binaries would go in /opt, your documentation would go in /var, etc. The idea that there's one single "your-app" directory that is selected by the user and contains everything related to the application is a Windows concept.

So anyway, the way to solve this in Linux is to install the various parts of your app in non-user-defined locations. That way you know exactly where your app would be if it was already installed.

Gabriel
Thanks Gabriel, that is a good strategy, but I wanted to know how one would accomplish that, specific to IzPack?
bguiz
That's just basic IzPack functionality... copying your binaries to various locations. Take a look at the packs element in the IzPack docs: http://izpack.org/documentation/installation-files.html#the-packs-element-packs
Gabriel
+1  A: 

I wrote this to allow my application to be installed over the jboss install.

public class JBossChecker {

 private static boolean tempJBossEnv;
 private static boolean tempJBossDirectoryExists;

 static {
  String s = System.getenv("JBOSS_HOME");
  tempJBossEnv= (s!=null);

  if( tempJBossEnv) {
   File f = new File(s);
   tempJBossDirectoryExists= ( f.exists() && f.isDirectory());
  }
  hasJBossEnv =tempJBossEnv;
  hasJBossDir = tempJBossDirectoryExists;
 }

 public static boolean hasJBossDir;
 public static boolean hasJBossEnv;

 public static void main(String[] args){
  System.out.println("Jboss environment "+hasJBossEnv);
  System.out.println("Jboss directory "+hasJBossDir);

 }
}

Then the installer has a section like

<conditions>
     <condition type="java" id="jbossEnv">
             <java> 
                 <class>au.com.codarra.ela.installer.JBossChecker</class
                 <field>hasJBossEnv</field>
             </java>
             <returnvalue type="boolean">true</returnvalue>
 </condition> 

 <condition type="java" id="jbossDir">
             <java>
                 <class>au.com.codarra.ela.installer.JBossChecker</class>
                 <field>hasJBossDir</field>
             </java>
             <returnvalue type="boolean">true</returnvalue>
 </condition> 

</conditions>

<installerrequirements>
 <installerrequirement condition="jbossEnv" message="Your system does not have the environment variable JBOSS_HOME set. Cannot update your system. Is XXXX installed on this system?" />
 <installerrequirement condition="jbossDir" message="Your system does not have a directory at the location in the environement variable JBOSS_HOME . Cannot update your system. Is XXXX installed on this system?" />
</installerrequirements>

<dynamicvariables>
 <variable name="INSTALL_PATH" value="${ENV[JBOSS_HOME]}"/>
</dynamicvariables>
<jar src="c:\dev\xxxx\build\installer.jar" />

The bit at the end makes sure izpack adds it to the installer jar.

Tim Williscroft
@Tim could you please indent/ reformat the java code? It's not getting parsed by SO.
bguiz
@Tim thanks for reformatting the code! I have another question: Where do you put your class, `JBossChecker` - how do you ensure it's loaded onto the classpath when the installer is run?
bguiz
The last line of code *jar* merges this jar into the izpack installer created. So it works as written.
Tim Williscroft
@Tim Williscroft I've asked another related question - would you happen to know other ways to invoke a Java class from izpack? http://stackoverflow.com/questions/2475527/calling-java-classes-from-izpack
bguiz
Izpack currently doesn't do other ways of accessing arbitrary java.But you can make event listeners for various izpack events and processing event listeners can get called in the processing panel.
Tim Williscroft