2013-05-09 135 views
2

我有一个问题,直到现在还找不到原因。Maven配置文件执行

我有一个有几个模块的maven项目。其中一个模块是webservices客户端。

因此,在开发过程中,当在maven中运行安装时,它需要访问本地服务器来生成客户端。当我运行插件来生成项目发布时,客户端应该指向生产服务器。

为此,我将其设置为一个关键属性$ {server.address},用于在生成客户端时指向服务器。有一个配置文件在激活时将此地址重写到生产服务器。

发生了什么事?运行mvn install会正确生成,即指向本地服务器。当我使用命令mvn release生成释放时:prepare -B release:perform -Denv = prd不会按照它应该重写该变量。

奇怪的是,如果我运行mvn install -Denv = prd,它会正确生成,指向生产服务器。

有人可以给我一个提示,要在发布周期中更改工作吗?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>groupId</groupId> 
    <artifactId>artifactId</artifactId> 
    <version>0.0.2-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <properties> 
     <server.address>http://localhost:8080</server.address> 
    </properties> 

    <profiles> 
     <profile> 
      <id>prd</id> 
      <activation> 
       <property> 
        <name>env</name> 
        <value>prd</value> 
       </property> 
      </activation> 
      <properties> 
       <server.address>http://srvprd009:8080</server.address> 
      </properties> 
      </profile> 
    </profiles> 

    <build> 
     <sourceDirectory>src/main/java</sourceDirectory> 
     <resources> 
      <resource> 
       <directory>src/main/resources</directory> 
      </resource> 
     </resources> 
     <testSourceDirectory>src/test/java</testSourceDirectory> 
     <testResources> 
      <testResource> 
       <directory>src/test/resources</directory> 
      </testResource> 
     </testResources> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-eclipse-plugin</artifactId> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-release-plugin</artifactId> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.cxf</groupId> 
       <artifactId>cxf-codegen-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>generate-client</id> 
         <phase>generate-sources</phase> 
         <configuration> 
          <sourceRoot>src/main/gen</sourceRoot> 
          <wsdlOptions> 
           <wsdlOption> 
            <wsdl>${server.address}/services/utilities?wsdl</wsdl> 
            <extraargs> 
             <extraarg>-p</extraarg> 
             <extraarg>${project.package}</extraarg> 
             <extraarg>-impl</extraarg> 
             <extraarg>-verbose</extraarg> 
             <extraarg>-frontend</extraarg> 
             <extraarg>jaxws21</extraarg> 
             <extraarg>-xjc-XhashCode</extraarg> 
             <extraarg>-xjc-Xequals</extraarg> 
            </extraargs> 
           </wsdlOption> 
          </wsdlOptions> 
         </configuration> 
         <goals> 
          <goal>wsdl2java</goal> 
         </goals> 
        </execution> 
       </executions> 
       <dependencies> 
        <dependency> 
         <groupId>org.apache.cxf</groupId> 
         <artifactId>cxf-rt-frontend-jaxws</artifactId> 
         <version>${cxf.version}</version> 
        </dependency> 
        <dependency> 
         <groupId>org.apache.cxf</groupId> 
         <artifactId>cxf-rt-transports-http</artifactId> 
         <version>${cxf.version}</version> 
        </dependency> 
        <dependency> 
         <groupId>org.jvnet.jaxb2_commons</groupId> 
         <artifactId>jaxb2-basics</artifactId> 
         <version>0.6.4</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-clean-plugin</artifactId> 
       <version>${maven-clean-plugin.version}</version> 
       <configuration> 
        <filesets> 
         <fileset> 
          <directory>src/main/gen</directory> 
          <includes> 
           <include>**/*.*</include> 
          </includes> 
         </fileset> 
        </filesets> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>build-helper-maven-plugin</artifactId> 
       <version>${build-helper-maven-plugin.version}</version> 
       <executions> 
        <execution> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>add-source</goal> 
         </goals> 
         <configuration> 
          <sources> 
           <source>src/main/gen</source> 
          </sources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>ts-core</artifactId> 
      <version>${project.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>corporate-tools.fragmental.security</groupId> 
      <artifactId>basic-ws-client</artifactId> 
      <version>${fragmental.version}</version> 
     </dependency> 

     <!-- JEE --> 
     <dependency> 
      <groupId>javax.j2ee</groupId> 
      <artifactId>j2ee</artifactId> 
      <version>1.4</version> 
      <scope>provided</scope> 
     </dependency> 

     <!-- JAX-WS --> 
     <dependency> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>1.1.1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.xml.bind</groupId> 
      <artifactId>jaxb-api</artifactId> 
      <version>${jaxws.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.xml.ws</groupId> 
      <artifactId>jaxws-api</artifactId> 
      <version>${jaxws.version}</version> 
      <exclusions> 
       <exclusion> 
        <groupId>javax.xml.soap</groupId> 
        <artifactId>saaj-api</artifactId> 
       </exclusion> 
       <exclusion> 
        <artifactId>jsr250-api</artifactId> 
        <groupId>javax.annotation</groupId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
    </dependencies> 
</project> 

回答

0

我固定我的问题创建两个配置文件,假设第一个具有德dafault激活= TRUE,并设置我的server.address为localhost。

是设置server.address到珠三角服务器的第二曲线由命令行直接-P珠三角称为

所以,当我不带任何参数执行,默认的配置文件设置server.address为localhost:8080当我执行发布时,我使用-P prd并且发布工作正常。

谢谢你的回答。

+1

您是否在每个版本中使用-Pprd?如果是,您可以将其添加到发布插件配置中,而不需要在命令行上手动设置它。请参阅http://maven.apache.org/maven-release/maven-release-plugin/perform-mojo.html#releaseProfiles – mszalbach 2013-05-09 20:45:00

1

发布插件有一个奇怪的(对我来说)使用具有特殊属性和转发他们到真正的目标执行。如果你使用正常的配置文件参数-Pprod,这将工作。但是,在mvn调用中添加的大多数其他参数都将被忽略。所以,你可以尝试以下方法之一:

mvn release:prepare -B release:perform -Darguments="-Denv=prd" 
0

我相信你使用的是Maven 2.0.x吧?

如果我没有记错,配置文件中的属性覆盖在Maven 2.0.7或之前无法正常工作。升级到最新的2.0.x(2.0.11)或甚至2.2.x/3.0.x将按照您的预期工作。

但是,有点偏离主题,我相信你正在访问服务器以获得WSDL的权利?我认为这不是一个好主意,特别是对于发布版本,因为它使得构建不可重现。考虑将WSDL与源代码放在一起(至少对于发布版本),以使构建可重现。

+0

我使用的是maven 3.0.3 – 2013-05-10 17:29:41