Exclude properties file from a WAR type sub-module in Maven

433 views Asked by At

I have a complex scenario of packaging my EAR projects, below is the sort of visual description to fully understand it:

ProjA.ear
 |-- ProjA.war
 |-- Util.war
 |   |-- WEB-INF
 |   |   |-- classes
 |   |   |   -- log4j.properties

Similarly, I have another project whose structure is:

ProjB.ear
 |-- ProjB.war
 |-- Util.war
 |   |-- WEB-INF
 |   |   |-- classes
 |   |   |   -- log4j.properties

Util.war is a common project (except log4j.properties) for both ProjA and ProjB.

Below is how I have specified the dependency of Util.war in both ProjA and ProjB:

    <dependency>
        <groupId>abc</groupId>
        <artifactId>xyz</artifactId>
        <version>${project.version}</version>
        <type>war</type>
    </dependency>

Now the question is: As I have different versions of log4j.properties file for each project, how can I configure Maven to add ProjA specific file while packaging ProjA and use the other version when packaging ProjB?

Please let me know if you don't understand the jumbled scenario :).

Regards,

1

There are 1 answers

0
StefanHeimberg On

i think you could remove your log4j.properties out of the Util.war because it is application depended. instead you could use the ProjA.ear/APP-INF/classes and ProjB/APP-INF/classes folder for this.

see What difference between app-inf and web-inf folders in JavaEE applications?

Your Application Server is adding this folder automatically to the Class-Path. But be aware of parent first / child first class loading

see Java EE and Java SE classloading

However, In Java EE, a classloader first tries to load the class itself and then delegate the classloading of that class to its parent classloader.

This statement is depending on your Application Server.