1

I'm using Eclipse and Maven on this project. I need to keep the log4j.properties file available for change after the code is packaged into a JAR file therefore I can't put that file in src/main/resources as mentioned in this post.

I found this post saying that I could add arguments to my Java call but I really wanted to do that by configuration (if possible, of course).

This reply to the first mentioned post was the closest solution I could find. It shows how to make properties files exported along with the JAR package file.

However I can't make it work when I put the properties file in a folder called CONF. Anyone can tell what I'm doing wrong? Check below my project structure and a portion of my pom.xml.

Project Structure .

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <targetPath>${basedir}/target</targetPath>
            <includes>
                <include>conf/log4j.properties</include>
                <include>conf/configuracoes.properties</include>
                <include>conf/aws.properties</include>
            </includes>
        </resource>
    </resources>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>br.com.aplicacao.ProgramLauncher</mainClass>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>./conf</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Sidney de Moraes
  • 993
  • 3
  • 11
  • 29

2 Answers2

1

Problem solved. Some lines were missing on my POM file, directly in the project tree.

<properties>
    <log4j.configuration>conf/log4j.properties</log4j.configuration>
</properties>
Sidney de Moraes
  • 993
  • 3
  • 11
  • 29
0

In my case the settings with the ./conf did not work with log4j , but after I changed to ./conf/ it was OK.

Jonnus
  • 2,988
  • 2
  • 24
  • 33