首页 > 解决方案 > 配置文件的Maven问题

问题描述

我尝试使用配置文件构建一个项目。

在 pom.xml 中,每个环境都有 3 个配置文件。例如,本地配置文件如下所示:

<profile>
 <id>local</id>
<build>
    <plugins>
      <plugin>
       <artifactId>maven-antrun-plugin</artifactId>
       <executions>
         <execution>
           <configuration>
             <tasks>
               <delete>
                <fileset dir="${project.build.outputDirectory}/wsdl" includes="*.wsdl" />
               </delete>
               <copy file="src/main/resources/wsdl/WebService-LOCAL.wsdl"
                     tofile="${project.build.outputDirectory}/wsdl/WebService.wsdl"/>
             </tasks>
           </configuration>
           <phase>package</phase>
           <goals>
             <goal>run</goal>
           </goals>
         </execution>
       </executions>
     </plugin>
        <plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>generate-stubs</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlUrls>
                          <wsdlUrl>http://localhost:8080/WebService/WebServiceBean?wsdl</wsdlUrl> 
                        </wsdlUrls>
                        <packageName>com.company.WebService.ws.generated</packageName>
                        <extension>true</extension>
                        <verbose>true</verbose>
                        <keep>true</keep>
                        <catalog>${basedir}/main/resources/catalog.xml</catalog>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.jvnet.jax-ws-commons
                                    </groupId>
                                    <artifactId>
                                        jaxws-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [2.2,)
                                    </versionRange>
                                    <goals>
                                        <goal>wsimport</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.apache.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-dependency-plugin
                                    </artifactId>
                                    <versionRange>
                                        [2.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>unpack</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
</profile>

当我运行以下命令时:

mvn clean package -P local

该项目已成功构建,但是,WebService.wsdl 被复制到 target/wsdl 文件夹中,而不是在生成的 jar 文件中,我仍然看到其他环境文件而不仅仅是 WebService.wsdl。在构建过程中我注意到jar文件是在环境文件的副本之前生成的,我怎样才能在jar文件生成之前将其复制?

标签: javamaven

解决方案


将您的插件绑定到较早的阶段,而不是包,而是之前的任何内容。


推荐阅读