Ericode
Ericode

Reputation: 136

Build a war and executable jar from maven

I am currently using maven for a project and I am trying to build an executable jar file and a war file from the same POM file. In the POM file I set the default packaging to be a war file and I have the 2 plugins below. The issue is the both generate a war/jar file (depending on what the global packaging is). How can I create a Jar and war file in the same POM.xml?

<plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-shade-plugin</artifactId>
       <version>3.2.1</version>
       <executions>
           <execution>
               <phase>package</phase>
               <goals>
                   <goal>shade</goal>
               </goals>
               <configuration>
                <packaging>jar</packaging>
                    <transformers>
                       <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                           <mainClass>main.java.com.test.Demo</mainClass>
                       </transformer>
                       <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                           <resource>META-INF/spring.handlers</resource>
                       </transformer>
                       <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                           <resource>META-INF/spring.schemas</resource>
                       </transformer>
                       <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer">
                       </transformer>
                       <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
                           <addHeader>false</addHeader>
                       </transformer>
                    </transformers>
              </configuration>
           </execution>
       </executions>
   </plugin> 

<plugin>            
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.2.2</version>
  <configuration>
    <packaging>war</packaging>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>    
  </configuration>
</plugin>

Upvotes: 0

Views: 2808

Answers (1)

Look at this https://stackoverflow.com/a/10863191 and try to use jar plugin.

I did what you want using something like that but unfortunately I do not have access to that code right now.

What maven command are you using to build your project?

Upvotes: 1

Related Questions