different log4j.xml when exporting jar from eclipse

I have problem when export to executable jar.

I'm using maven and slf4j with log4j

My pom.xml

<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>1.7.2</version>
   <scope>runtime</scope>
</dependency>

I added a log4j.xml in /src/java/main (is the same that in generated target folder):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/media/dlm/log/dlm.log" />
    <param name="Threshold" value="INFO" />
    <param name="Append" value="false" />
    <param name="MaxFileSize" value="10MB" />
    <param name="MaxBackupIndex" value="1" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m %n" />
    </layout>
</appender>

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out" />
    <param name="Threshold" value="INFO" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern"
            value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m %n" />
    </layout>
</appender>


<root>
    <level value="INFO" />
    <appender-ref ref="FILE" />
</root>

</log4j:configuration>

But when I export from eclipse the log4j.xml is changed for the next one:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/tmp/dlm/log4j.log" />
    <param name="Threshold" value="INFO" />
    <param name="Append" value="false" />
    <param name="MaxFileSize" value="1MB" />
    <param name="MaxBackupIndex" value="1" />

    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %-5p %X{service} %X{user} [%c] %m%n" />
    </layout>
</appender>

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out" />
    <param name="Threshold" value="ERROR" />

    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern"
            value="%d{ABSOLUTE} %-5p %X{service} %X{user} [%c{1}] %m%n" />
    </layout>
</appender>


<root>
    <level value="INFO" />
    <appender-ref ref="CONSOLE" />
</root>
</log4j:configuration>

I tried using log4j.properties file as appear here, but nothing.

Thanks in advance your answers.

Answers


Thanks to Peter I understood that when run an aplicacition with eclipse I was using eclipse options and not maven itself to build my app. That was the reason log4j.xml probably change. The next solution not resolve why it happens, but resolve the problem and give me a correct way to build my app using 100% maven.

I just need to add some new fields to my pom.xml to make things that eclipse options probably add automatically.

1.-Include xml files:

<build>
...
<!-- RECURSOS -->
<resources>
    <resource>
    <directory>src/main/java</directory>
    <includes>
        <include>**/*.fxml</include>
        <include>log4j.xml</include>
    </includes>
    </resource>
</resources>
...
</build>

2.- Executable jar (I have 3 different main classes in same project):

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
  <archive>
    <manifest>
      <mainClass>${class.main}</mainClass>
    </manifest>
  </archive>
  <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
  </descriptorRefs>
</configuration>
</plugin>

3.- Add profiles to select main class:

<profiles>
<!-- DLM ANALOG -->
<profile>
  <id>dlmdesktopanalog</id>
  <properties>        
    <class.main>cl.icpdas.dlm.desktop.fx.main.analog.DataLoggerAnalogManager</class.main>
  </properties>
</profile>
<!-- DLM DIGITAL -->
<profile>
  <id>dlmdesktopdigital</id>
  <properties>
    <class.main>cl.icpdas.dlm.desktop.fx.main.digital.DataLoggerDigitalManager</class.main>
  </properties>
</profile>
<!-- DLM EXTRACTOR -->
<profile>
  <id>dlmdesktopextractor</id>
  <properties>
    <class.main>cl.icpdas.dlm.desktop.fx.main.extractor.DataLoggerExtractorManager</class.main>
  </properties>
</profile>
</profiles>

Finally, I used the next goals make my executable jar.

mvn clean package assembly:single -e -P dlmdesktopanalog

Anyway, if someone knows where eclipse set log4j.xml and other options when make a exejutable jar or what is reasson why it changes log4j.xml the answers are wellcome as comment.


Need Your Help

Java Future and infinite computation

java future

I'm trying to optimize an (infinite) computation algorithm.

Programmatically creating a clickable area on an image

wpf code-behind imagemap

I'm trying to create "imagemaps" on an image in wpf using codebehind.