Distribute XSD files over multiple Maven Artifacts

前端 未结 1 921
滥情空心
滥情空心 2021-02-09 10:34

Here is a small Example of what I would like to achieve:

Maven Artifact A is one of many Webservices and defines a XSD Schema with definitions for Requests and Response

1条回答
  •  一生所求
    2021-02-09 11:19

    I think your question is reasonable. In the past I have often found that I have a Maven module that needs to do special processing on files that can be found in dependent JARs.

    What I have done in the past is to make Artifact B a dependency of Artifact A. Then in the pom.xml of Artifact A I use a special configuration of the Maven dependency plugin as follows:

    
        
        org.apache.maven.plugins
        maven-dependency-plugin
        
              
                  unpack-xsd-files
                  
                  initialize
                       
                           unpack
                       
                       
                            
                                
                                    
                                    com.mycorp
                                    artifact-b
                                    ${artifact-b.version}
                                    jar
                                
                             
                             **/*.xsd
                             ${project.basedir}/target/xsd-includes
                       
                
        
    
    

    Now your XSD files of interest can be found in the target directory of Artifact A and from there you can do anything you want with them. You can include them as resources, reference them from other XSD files, embed them in your own JARs or whatever! As you can see from the configuration, you also don't have to put them in your target directory; you could put them directly into your /src/main/resources directory.

    You can add this configuration to any Maven module you want so that multiple modules can all work the same way. The nice thing about this approach is that it will also work from with Eclipse via M2Eclipse.

    0 讨论(0)
提交回复
热议问题