How to set Environment variable from pom in install phase


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.


enter image description here

POM part calling fx packager which call candel

                        <target name="installers" xmlns:fx="">

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

                            <fx:deploy nativeBundles="all" width="600" height="400" 
                                outdir="${}/dist" outfile="${}"

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

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

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

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

                                <fx:platform javafx="${javafx.version}" basedir="${java.home}">
                                    <fx:jvmarg value="-Xms512m" />
                                    <fx:jvmarg value="-Xmx1024m" />
                                <fx:permissions elevated="true" />
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:

    <!-- copy resources -->

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.


`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.

11/6/2014 5:28:02 PM

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