简体   繁体   中英

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

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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM