How to remove version number from war file

2019-04-11 10:20发布

I have a Dependency in child pom like this.

<dependencies>
        <dependency>
            <groupId>sample-groupID</groupId>
            <artifactId>sfint</artifactId>
            <version>1.0.0-SNAPSHOT</version>  
            <type>war</type>                
        </dependency>
</dependencies>

And I am using maven-ear-plugin.

 <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven.ear.plugin</artifactId>
    <version>2.10</version>
    <configuration>
            <modules>
                <webModule>
                    <groupId>sample-gropuID</groupId>
                    <artifactId>sfint</artifactId>
                    <version>1.0.0-SNAPSHOT</version>
                    <moduleID>WebModule_sfint</moduleID>
                    <bundleFileName>sfint.war</bundleFileName>  
                </webModule>
            </modules>  
    </configuration>
  </plugin>

Now my problem is that I want my war file to be like this - sfint.war but I am getting it as - sfint.1.0.0-SNAPSHOT.war

Any help ??

5条回答
Melony?
2楼-- · 2019-04-11 10:54

If the war/ejb is part of an ear project, one should use bundleFileName to change the module names in the final ear artifact.

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-ear-plugin</artifactId>
   <version>${version.ear.plugin}</version>
   <configuration>
     <modules>
       <webModule>
         <groupId>com.foo</groupId>
         <artifactId>myapp-web</artifactId>
         <contextRoot>/myapp</contextRoot>
         <bundleFileName>myapp-web.war</bundleFileName>
       </webModule>
       <ejbModule>
         <groupId>com.foo</groupId>
         <artifactId>myapp-ejb</artifactId>
         <bundleFileName>myapp-ejb.jar</bundleFileName>
       </ejbModule>
     </modules>
   </configuration>
 </plugin>
查看更多
SAY GOODBYE
3楼-- · 2019-04-11 10:55

Within the <build> tag specify the name that you need for the artifact as "finalName".

<build>
    <finalName>sfint</finalName>
</build>
查看更多
叛逆
4楼-- · 2019-04-11 11:00

This will solve your problem:

    <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>myEAR</groupId>
  <artifactId>myEAR</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>ear</packaging>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.10</version>
        <configuration>
          <earSourceDirectory>EarContent</earSourceDirectory>
          <generateApplicationXml>false</generateApplicationXml>
          <version>6</version>
          <defaultLibBundleDir>lib</defaultLibBundleDir>
          <fileNameMapping>no-version</fileNameMapping>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>myWAR</groupId>
        <artifactId>myWAR</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>war</type>
    </dependency>
  </dependencies>
</project>

your final EAR will be myEAR-0.0.1.SNAPSHOT.EAR that contains myWAR.war (without version number) if you want to remove version number from EAR also than add myEar

查看更多
叼着烟拽天下
5楼-- · 2019-04-11 11:01

You can configure maven-ear-plugin to omit the version information in the EAR file:

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.10.1</version>
        <configuration>
           [...]
           <fileNameMapping>no-version</fileNameMapping>
        </configuration>
      </plugin>
    </plugins>
  </build>
查看更多
聊天终结者
6楼-- · 2019-04-11 11:02
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <outputFileNameMapping>@{artifactId}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping>
查看更多
登录 后发表回答