How to set Environment variable from pom in install phase


Question

I am making an installer with WIX Tool Set by using with maven. My Wix confg file 'WXS' needs the current project directory path. Basically javafx packager tool take WXS file and put in a temp folder and then made installers so i need to give path of project directory. I can not statically define. so i need to specify absolute path of project directory. Maven's ${project.builddir} has this path. so i need to set this path in environment variable so that WIX latter can use this.

Can any body tell me how can i set environment variable during install phase. And it should only set when build runs on windows. because my maven build run 3 times. one for windows one for mac and one for Linux O.S. to create respective installers. so if it runs on windows then on install phase it should set the environment variable and after that my installer plugin which is maven ant plugin should run.

I just need to know the setting of environment variable from POM and it should only works if build runs in windows.

Edit

enter image description here

POM part calling fx packager which call candel

<execution>
                    <id>create-deployment-bundle</id>
                    <phase>install</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target name="installers" xmlns:fx="javafx:com.sun.javafx.tools.ant">

                            <taskdef uri="javafx:com.sun.javafx.tools.ant" resource="com/sun/javafx/tools/ant/antlib.xml"
                                classpath="${project.basedir}:${javafx.tools.ant.jar}" />

                            <fx:deploy nativeBundles="all" width="600" height="400" 
                                outdir="${project.build.directory}/dist" outfile="${project.build.finalName}"
                                verbose="true">

                                <fx:application name="${project.build.finalName}"
                                    mainClass="${javafx.main.class}" />

                                <fx:resources>
                                    <fx:fileset dir="${project.build.directory}"
                                        includes="${project.build.finalName}.jar" />
                                    <fx:fileset os="windows" type='license' includes="Licence.rtf" dir="${basedir}/package/macosx" />
                                </fx:resources>

                                <fx:preferences shortcut="true" menu="true"
                                    install="true" />

                                <fx:info title="${application.title}" vendor="${application.vendor}"
                                    copyright="${application.copyright}" description="${application.description}">
                                </fx:info>

                                <fx:platform javafx="${javafx.version}" basedir="${java.home}">
                                    <fx:jvmarg value="-Xms512m" />
                                    <fx:jvmarg value="-Xmx1024m" />
                                </fx:platform>
                                <fx:permissions elevated="true" />
                            </fx:deploy>
                        </target>
                    </configuration>
                </execution>
1
0
11/7/2014 6:36:16 AM

You can use the Maven resources plugin to enable filtering on your *.wxs file(s) so that you can use Maven properties directly in your WiX project.

Example plugin entry in your POM file:

<plugin>
    <!-- copy resources -->
    <artifactId>maven-resources-plugin</artifactId>
    <groupId>org.apache.maven.plugins</groupId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>installer</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.basedir}/package/windows</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <includes>
                            <include>**/*.wxs</include>
                        </includes>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

Enable filtering of files by setting <filtering>true</filtering>, which will process all files input to the copy plugin and replace all Maven property references with their values. The directory between <directory> tags is the location of your WiX project files. The output directory is where the filtered result will be placed.

In your WiX project file you can specify this:

<Property Id="MYPROJECTROOTPATH" Value="${project.builddir}"/>

After filtering, it will look (something) like this:

<Property Id="MYPROJECTROOTPATH" Value="C:\your\project\dir\target"/>

When you compile your MSI, you use the new location of the filtered WXS file for candle and then it should allow you to do what you want without having to specify environment variables.

Doing it this way removes the dependency on your OS's handling of environment variables

Another alternative method is to use the -d option to candle to define a preprocessor variable.

Ex:

`candle -dRPAS_JAVA=${project.builddir} ...`

from within your POM file (I don't know how you're actually calling candle/light), you can use the build directory as a variable and in your WXS file, you'd change env.RPAS_JAVA to var.RPAS_JAVA. This effectively accomplishes the same thing, but I like the filtering method because it means my command line rarely has to change.

1
11/6/2014 5:28:02 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon