سؤال

I have a Maven project that generates a WAR file and tries to get the artifact version from properties in .properties files that are maintained in the codebase. I also try to form the final name of the WAR file using custom properties.

Snippet :

<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>com.xyz.webapps</groupId>
  <artifactId>webapps</artifactId>
  <version>${info.version}-${application.env}</version>
  <packaging>war</packaging>
  <!-- Filling in the artifact version with properties read below -->

   ...

  <!-- Filling in the WAR name -->
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <maven.war.final.name>${pom.artifactId}-${pom.currentVersion}.war</maven.war.final.name>
     <maven.test.skip>true</maven.test.skip>
   </properties>

 ...

 <build>
   <plugins>

   ...

   <!-- I read those properties files here -->
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>${project.basedir}/webapps-main/src/main/resources/MessageResources.properties</file>
            <file>${project.basedir}/build.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

  ...

 </plugins>

...
</project>

The name of the WAR file gets generated properly when I do a "mvn clean package" :

[INFO] Assembling webapp[webapps] in [/home/jubuntu/workspace/ui/new/webapps/target/webapps-2.8-qa]
[INFO] Processing war project
[INFO] Copying webapp resources[/home/jubuntu/workspace/ui/new/webapps/webapps-main/src/main/webapp]
[INFO] Webapp assembled in [4690 msecs]
[INFO] Building war: /home/jubuntu/workspace/ui/new/webapps/target/webapps-2.8-qa.war

But when I do a "mvn clean install" ( or a "mvn clean deploy" ) , the properties don't expand for some reason (the package phase still generates the WAR with the right name) :

[INFO] Building war: /home/jubuntu/workspace/ui/new/webapps/target/webapps-2.8-qa.war
[INFO] [install:install {execution: default-install}]
[INFO] Installing /home/jubuntu/workspace/ui/new/webapps/target/webapps-2.8-qa.war to /home/jubuntu/.m2/repository/com/xyz/webapps/webapps/${info.version}-${application.env}/webapps-${info.version}-${application.env}.war

Is there something wrong that I'm doing here ? How would I make this work for installing and deploying my artifact ? I use maven version 2.2.1 for my builds. Thanks.

هل كانت مفيدة؟

المحلول

You can't do this. It's not supported by Maven. It's fundamental.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top