[izpack-user] Parsing and variable substitution inside a JAR

115 views
Skip to first unread message

Sebastien ARBOGAST

unread,
Jun 26, 2008, 11:04:54 AM6/26/08
to us...@izpack.codehaus.org
Hi everyone,

I'm creating an installer for an Eclipse RCP-based application and I need the installer to substitute variables inside a JAR. The JAR is one of the plugins of my application and I can't deploy it in exploded mode because paths are too long. Is it possible to parse properties file inside a JAR like that?

--
Sébastien Arbogast

http://sebastien-arbogast.com

Andrew Warinner

unread,
Jun 26, 2008, 11:16:44 AM6/26/08
to us...@izpack.codehaus.org
On Thu, Jun 26, 2008 at 5:04 PM, Sebastien ARBOGAST
<sebastien...@gmail.com> wrote:
> Hi everyone,
>
> I'm creating an installer for an Eclipse RCP-based application and I need
> the installer to substitute variables inside a JAR. The JAR is one of the
> plugins of my application and I can't deploy it in exploded mode because
> paths are too long. Is it possible to parse properties file inside a JAR
> like that?

I am interested in doing this as well (substituting variables in a
web.xml file in a war) so I second the motion.

I was contemplating extracting the contents of the war, doing the
substitution and then reassembling it in an executable but I am
looking for a better way.

Andrew Warinner

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Sebastien ARBOGAST

unread,
Jun 26, 2008, 11:59:20 AM6/26/08
to us...@izpack.codehaus.org
The same here. And I insist on the fact that extracting the JAR, parsing and rejarring the whole thing, even automatically with something like a custom panel would not do it for me as the JAR extraction would fail on windows because paths are longer than 256 characters.

2008/6/26 Andrew Warinner <awar...@gmail.com>:

Mark van Holsteijn

unread,
Jun 26, 2008, 1:49:37 PM6/26/08
to us...@izpack.codehaus.org
I would recommend using truezip (https://truezip.java.dev.net). It is a faboulous library that makes the archive look lik a virtual file system. No need to extract and rejar.


Cheers,

Mark
--
ing.Mark van Holsteijn
senior consultant
Equi Librio Consultancy & Coaching BV.
tel: +316-22-374-114

Mark van Holsteijn

unread,
Jun 26, 2008, 1:55:34 PM6/26/08
to us...@izpack.codehaus.org
At my customer site, I created a very small 'configurator' utility that is capable of handling environment specific configuration of any archive, recursively. The configurator is invoked by the izpack installer using an ant task. If you are interested in the solution, please let me know.

Cheers,

Mark
--
ing.Mark van Holsteijn
senior consultant
Equi Librio Consultancy & Coaching BV.
tel: +316-22-374-114, ma...@equilibrio-consultancy.com

Sebastien ARBOGAST

unread,
Jun 26, 2008, 5:34:57 PM6/26/08
to us...@izpack.codehaus.org
Is it possible to inject user input variables in your configurator?
Otherwise, how hard would it be to implement another parse type, like an "archive" parse type that would make it possible to substitute variables in files with a URL like "$INSTALL_PATH/plugins/com.myapp.myplugin.jar!config.properties"?

2008/6/26 Mark van Holsteijn <mark.van....@gmail.com>:

Mark van Holsteijn

unread,
Jun 27, 2008, 5:24:44 AM6/27/08
to us...@izpack.codehaus.org
Input variables can specified by using property files and as system properties.
 
You can probably do what you want to do transparantly, by using truezip's virtual file system to do the io for all current parse types. In this case, you just specify the target file in the normal fashion $INSTALL_PATH/plugins/com.myapp.myplugin.jar/config.properties.
 
Cheers,
 
Mark

Sebastien ARBOGAST

unread,
Jun 27, 2008, 7:23:18 AM6/27/08
to us...@izpack.codehaus.org
OK, I tried to do as you suggested. I'm customizing com.izforge.izpack.installer.ScriptParser. The only thing I had to modify is the parseFiles method:

public void parseFiles() throws Exception {
        // Parses the files
        Iterator<ParsableFile> iter = files.iterator();
        while (iter.hasNext()) {
            // If interrupt is desired, return immediately.
            if (Unpacker.isInterruptDesired()) {
                return;
            }
            // Create a temporary file for the parsed data
            // (Use the same directory so that renaming works later)
            ParsableFile pfile = iter.next();

            // check whether the OS matches
            if (!OsConstraint.oneMatchesCurrentSystem(pfile.osConstraints)) {
                continue;
            }

            de.schlichtherle.io.File file = new de.schlichtherle.io.File(pfile.path);
            System.out.println("source file: " + file.getAbsolutePath() + "(" + file.exists() + ")");
            java.io.File tempFile = java.io.File.createTempFile("izpp", null, null);
            de.schlichtherle.io.File parsedFile = new de.schlichtherle.io.File(tempFile);
            BufferedInputStream in;
            BufferedOutputStream out;
            de.schlichtherle.io.FileInputStream inFile = new de.schlichtherle.io.FileInputStream(file); //FileNotFoundException thrown here
            in = new BufferedInputStream(inFile, 5120);
            FileOutputStream outFile = new FileOutputStream(parsedFile);
            out = new BufferedOutputStream(outFile, 5120);
            vs.substitute(in, out, pfile.type, pfile.encoding);
            in.close();
            out.close();
            file.delete();
            if (!parsedFile.renameTo(file)) {
                throw new IOException("Could not rename file " + parsedFile + " to " + file);
            }
        }
    }

Here is my parsable in my installer descriptor:

<parsable targetfile="$INSTALL_PATH/plugins/com.mycompany.myapp_1.0.0.jar/myapp.properties"
                type="javaprop"/>

But when I run the installer I get the following exception:

java.io.FileNotFoundException: C:\Program Files\KMC Client\plugins\com.mycompany.myapp_1.0.0.jar\myapp.properties (The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at de.schlichtherle.io.FileInputStream.createInputStream(FileInputStream.java:138)
        at de.schlichtherle.io.FileInputStream.<init>(FileInputStream.java:108)
        at com.izforge.izpack.installer.ScriptParser.parseFiles(ScriptParser.java:159)
        at com.izforge.izpack.installer.Unpacker.run(Unpacker.java:444)
        at java.lang.Thread.run(Thread.java:619)

And I've double checked: the JAR exists and the properties file is well inside.

Any idea of what is going on?

2008/6/27 Mark van Holsteijn <mark.van....@gmail.com>:

Daniel Schimikowski

unread,
Jun 27, 2008, 7:52:44 AM6/27/08
to us...@izpack.codehaus.org
Maybe this will help:
When accessing files inside a jar the file separator inside a jar is
always "/". Never "\". But if you use File.separator under windows, it
will try to use "\" and will fail.


Yours Daniel

--
Forschungsgesellschaft für Angewandte Naturwissenschaften e.V. (FGAN)

Forschungsinstitut für Kommunikation, Informationsverarbeitung und
Ergonomie (FKIE)

Abteilung Ergonomie und Mensch-Maschine-Systeme (EMS)

Neuenahrer Straße 20, 53343 Wachtberg, Germany

Tel.: +49 (0228) 9435 470

Fax: +49 (0228) 9435 508
E-Mail: schimi...@fgan.de

Web: www.fgan.de/fkie-ems

**********************************

Sitz der Gesellschaft: Bonn

Registergericht: Amtsgericht Bonn VR 2530

Vorstand: Dr. rer. Nat. Ralf Dornhaus (Vorsitzender), Prof. Dr. Joachim
Ender (Stellvertreter)

Sebastien ARBOGAST

unread,
Jun 27, 2008, 6:12:15 PM6/27/08
to us...@izpack.codehaus.org
In fact, I had made a mistake in integrating TrueZip libraries in IZPack's build. Now I solved it and it works great. I just submitted a patch for it: http://jira.codehaus.org/browse/IZPACK-118

2008/6/27 Daniel Schimikowski <schimi...@fgan.de>:

Julien Ponge

unread,
Jun 29, 2008, 6:24:45 AM6/29/08
to us...@izpack.codehaus.org
Thanks Sebastien, I will review your patch shortly (but not next week)
unless another IzPack developer wants to pick it up!

I'm scheduling it for 4.1.0.

BTW did we met at JavaOne???

Reply all
Reply to author
Forward
0 new messages