[izpack-users] Usage of Loose Packs

Stefan Wachter Stefan.Wachter at gmx.de
Fri May 12 19:27:37 CEST 2006


Hi Joerg,

unfortunately nobody reacted. Therefore I looked into AntInstaller and 
found a nice solution there. If you know that a specific class is 
packaged in the setup jar then you can get that class as a resource. 
Then you do some file name manipulation to get the file name of the 
setup jar. Finally you can derive the folder where the setup jar resides 
in and address other files inside that folder. Here is some code snippet:

    URL jarUrl = 
getClass().getResource("/de/vdp/ant/IzPackDetermineJarTask.class"); // 
class contained in setup jar
    String stringForm = jarUrl.toString();
    String fileForm = jarUrl.getFile();
   
    File jarFile = null;
    int endIdx = stringForm.indexOf("!/");
    if (endIdx == -1) {
      throw new BuildException("Can't locate the jar file - url: '" + 
stringForm + "'");
    }
    String unescaped = null;
    String fileNamePart = stringForm.substring("jar:file:".length(), 
endIdx);
    jarFile = new File(fileNamePart);
    if (!jarFile.exists()) {
      // try to unescape the URL Handler has escaped the " " to %20
      unescaped = unescape(fileNamePart);
      jarFile = new File(unescaped);
      if (!jarFile.exists()) {
        throw new BuildException("Can't locate the jar file - tried: '" 
+ fileNamePart + "' and '" + unescaped + "'");
      }
    }
    File setupDirectory = jarFile.getParentFile();

I use that code in an Ant task to set a property. Ideally someone would 
integrate this kind of code into IzPack and set a built-in variable, 
e.g. SETUP_DIRECTORY.

--Stefan


PS: Here's the code for unescape

  private static String unescape(final String s) {
    StringBuffer sb = new StringBuffer(s.length());
   
    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      switch (c) {
        case '%': {
          try {
            sb.append( (char) Integer.parseInt(s.substring(i + 1, i + 
3), 16));
            i += 2;
            break;
          } catch (NumberFormatException nfe) {
            throw new IllegalArgumentException();
          } catch (StringIndexOutOfBoundsException siob) {
            String end = s.substring(i);
            sb.append(end);
            if (end.length() == 2) i++;
          }
          break;
        }
        default: {
          sb.append(c);
          break;
        }
      }
    }
    return sb.toString();
  }

Joerg Fackler wrote:
> Hello,
>
> did you gained some information about that topic? For me
> this is interesting too.
>
> Best regards, Joerg
>
>> Hi all,
>>
>> I tried for hours to get a loose package working.
>>
>> The problem occurs during installation. What is the correct value 
>> forthe "dir" attribute in a fileset of a loose package?
>>
>> Assuming that in the same directory where the setup.jar is located 
>> thereare a couple of WAR files that are to be copied into the webapps 
>> folderof the installation directory. The following does not the job. 
>> It seemsthat the specified dir (".") is resolved relatively to the 
>> basedir that was specified during compiling the setup. Yet, the 
>> basedir used duringcompilation can definitely not be used during 
>> installation!
>>
>> Best regards,
>> --Stefan
>>
>>    <pack name="wars" required="yes" loose="true">
>>      <description/>
>>      <fileset dir="." includes="*.war" 
>> targetdir="$INSTALL_PATH/webapps"/>
>>    </pack>
> _______________________________________________
> izpack-users mailing list
> izpack-users at lists.berlios.de
> http://lists.berlios.de/mailman/listinfo/izpack-users
>
>




More information about the izpack-users mailing list