0

I made a maven project and are using slf4j with log4j. Also I am using jibx bindings.

src/main/java is my class folder src/main/config folder for jibx bindings and generated classes

both are declared as source folders

the log4j.properties is in the classpath (irelevant if it ist in java or config)

Here is the situtation: log4j works. I can start the programm out of eclipse or through the created jar file (maven) and logging works. But when I start "maven clean" and build the project again and start I get "log4j:WARN No appenders could be found for logger" Happens with starting out of eclipse or through jar file. The log4j.propeties won't be copied to target/classes and it will not be in the jar file. I move the log4j.properties in Eclipse from example java folder to config folder and back. Compile with maven again. The properties is in the classes folder and in the jar. I always have to do this after maven clean! I don't know why the properties is missing after clean. It's still in a folder in classpath. I don't change anything. Anyone have an idea how to fix it? It's realy disturbing. Thx to jibx it is nessesary to clean from time to time. I searched with google and only found problems with that when properties is NOT in classpath. But in my case it is.

If I missed any needed informations ask for it, please :)

EDIT: Argh, yes. properties not in resource folder was the problem. Fixed.

But still strange behavior if properties is not in resource folder. Even in Eclipse log4j stopps working after maven clean. And works again after moving properties around and back to beginning folder.

2 Answers2

2

Property files like this have to be located into src/main/resources for production. If you like to have a different configuration for unit testing than put it into src/test/resources.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
0

You can specify the maven to read the resources from the src/test/main by configuring the <build> tag in pom.xml

We can place test case even in the src/main/java/test and make it run during build by configuring <testSourceDirectory> tag

We can read properties from any location in project by configuring <testResources> tag

<build>     
        <testSourceDirectory>${basedir}/src/test/java/logical</testSourceDirectory>
        <testResources>
            <testResource>
                <directory>${basedir}/src/main/resources/</directory>
                <includes>
                    <include>*</include>
                </includes>             
            </testResource>
        </testResources>
</build>        
om39a
  • 1,406
  • 4
  • 20
  • 39