log4j configuration file in a multi-module Maven project

前端 未结 3 1590
生来不讨喜
生来不讨喜 2020-12-28 17:19

I am working on a multi-module Maven project, whose structure is like this:

war-module
jar-module

The war-module depends on the jar-module,

3条回答
  •  -上瘾入骨i
    2020-12-28 18:20

    In the jar module, exclude the file from the jar:

    
        org.apache.maven.plugins
        maven-jar-plugin
        2.3.1
        
          
            log4j.xml
          
        
    
    

    Use the buildhelper plugin to attach the log4j.xml to the build as a separate artifact

    
        org.codehaus.mojo
        build-helper-maven-plugin
        1.5
        
          
            attach-artifacts
            package
            
              attach-artifact
            
            
              
                
                  ${project.build.outputDirectory}/log4j.xml
                  xml
                  log4j
                
              
            
          
        
    
    

    Now in your war artifact, copy the xml to the output directory:

    
        org.apache.maven.plugins
        maven-dependency-plugin
        
          
            copy
            prepare-package
            
              copy
            
            
              
                
                  ${project.groupId}
                  your.jar.project.artifactId
                  ${project.version}
                  xml
                  log4j
                  ${project.build.outputDirectory}
                  
                  log4j.xml
                
              
            
          
        
    
    

    But of course it would be easier to just put the file in [web-artifact]/src/main/resources in the first place :-)

提交回复
热议问题