1

As logging-tool I am using Log4j2 and this is invoked by using a system property (/VM argument), using:

-Dlog4j.configurationFile=./config/log4j2_config.xml

For compiling my projects I am using Maven and to create exe-files Launch4j (Plugin: com.akathist.maven.plugins.launch4j).

The plugin definition in my pom.xml looks like that:

<plugin>
    <groupId>com.akathist.maven.plugins.launch4j</groupId>
    <artifactId>launch4j-maven-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>l4j-clui</id>
            <phase>package</phase>
            <goals>
                <goal>launch4j</goal>
            </goals>
            <configuration>
                <headerType>gui</headerType>
                <cmdLine>./config/MyConfig.xml</cmdLine>
                <opt>com.akathist.maven.plugins.launch4j.configurationFile=./config/log4j2_config.xml</opt>
                <jar>${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar</jar>
                <outfile>${project.build.directory}/MyExe.exe</outfile>
                <downloadUrl>http://java.com/download</downloadUrl>
                <classPath>
                    <mainClass>de.my.path.MainClass</mainClass>
                    <!-- <preCp>anything</preCp> -->
                </classPath>
                <!-- <icon>${project.basedir}/src/main/assembly/application.ico</icon> -->
                <jre>
                    <minVersion>1.7.0_00</minVersion>
                    <!-- <jdkPreference>preferJre</jdkPreference> -->
                </jre>
            </configuration>
        </execution>
    </executions>
</plugin>

My question is now:

How can I set the system property for the log4j2 integration?!

If tried to put it in brackets with "opt" (http://launch4j.sourceforge.net/docs.html)

or something like that:

                        <vars>
                            <var>-Dlog4j.configurationFile=./config/log4j2_config.xml</var>
                        </vars>

But both did not work and my logger wasn't logging..

Maybe you had the same problem and can help me.

Thank you for your help!

mrbela
  • 4,477
  • 9
  • 44
  • 79

2 Answers2

2

I'm not familiar with launch4j or the maven plugin, but according to the Ant docs, you specify System Properties with <opt> tags. And the maven plugin docs say that the pom structure is similar, so did you try using <opt> tags inside the <jre> tags?

like

    <jre>
        <opt>-Dlog4j.configurationFile=./config/log4j2_config.xml</opt>
    </jre>

Try that, and let me know if it works.

Now a question:

Is there a reason that you are using a different name for your config? Normally the filename is log4j2.xml. If you use that name, the config should automatically be loaded and you don`t need the system property.

rewolf
  • 5,561
  • 4
  • 40
  • 51
  • 1
    Hey! the first opportunity didn't work.. Rename the file in log4j2.xml and put it in the src folder (http://stackoverflow.com/questions/25487116/log4j2-configuration-no-log4j2-configuration-file-found) worked!! For now, I've written the author of the plugin, because the opportunity to add system propoerties should be possible and is a little bit nicer solution, in my opinion.. ;) – mrbela Feb 24 '15 at 11:18
-1
<opts>
    <opt>-Dlog4j.configuration=file:log4j.xml</opt>
</opts>
Adam Michalik
  • 9,678
  • 13
  • 71
  • 102
Chacho
  • 1