How to remove version number from war file

我与影子孤独终老i 提交于 2019-12-30 04:46:26

问题


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 ??


回答1:


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

<build>
    <finalName>sfint</finalName>
</build>



回答2:


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>



回答3:


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <outputFileNameMapping>@{artifactId}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping>



回答4:


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:


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>


来源:https://stackoverflow.com/questions/33411621/how-to-remove-version-number-from-war-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!