Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate War file using Maven [duplicate]

Tags:

I have a maven pom as follows:

<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/maven-v4_0_0.xsd">   <modelVersion>4.0.0</modelVersion>   <groupId>MerchantWallet</groupId>   <artifactId>StellarReceive</artifactId>   <packaging>war</packaging>   <version>0.0.1-SNAPSHOT</version>   <name>StellarReceive Maven Webapp</name>   <url>http://maven.apache.org</url>   <properties>     <spring.version>4.3.8.RELEASE</spring.version>     <jdk.version>1.8</jdk.version> </properties>  <dependencies>        <dependency>             <groupId>jstl</groupId>             <artifactId>jstl</artifactId>             <version>1.2</version>         </dependency>      <dependency>     <groupId>org.springframework</groupId>     <artifactId>spring-jdbc</artifactId>     <version>${spring.version}</version> </dependency>      <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-core</artifactId>         <version>${spring.version}</version>     </dependency>      <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-web</artifactId>         <version>${spring.version}</version>     </dependency>      <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-webmvc</artifactId>         <version>${spring.version}</version>     </dependency> <!-- hello -->     <dependency>         <groupId>junit</groupId>         <artifactId>junit</artifactId>         <version>3.8.1</version>         <scope>test</scope>     </dependency>      <dependency>     <groupId>mysql</groupId>     <artifactId>mysql-connector-java</artifactId>     <version>5.1.6</version> </dependency>   </dependencies>  <build>     <finalName>StellarReceive</finalName>     <plugins>          <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-compiler-plugin</artifactId>             <version>3.0</version>             <configuration>                 <source>${jdk.version}</source>                 <target>${jdk.version}</target>             </configuration>         </plugin>     </plugins> </build>  </project> 

I dont see a .war file in the target folder. Can someone please help

Here is my folder structure: enter image description here

like image 928
TimeToCodeTheRoad Avatar asked Jun 01 '17 02:06

TimeToCodeTheRoad


People also ask

How can a war file be generated using a single command?

You need to use -c switch of jar, to create the war file. Go inside the project directory of your project (outside the WEB-INF), then write the following command: jar -cvf projectname. war *

How do I add war inside my ear with Maven?

if you have EAR file you can unpack it: maven.apache.org/plugins/maven-ear-plugin/examples/… and then add war, change application. xml and pack it again.


2 Answers

First you must define your project with as packaging of war type:

<groupId>...</groupId> <artifactId>...</artifactId> <version>...</version> <packaging>war</packaging> 

Then you will need to use the maven plugin to generate the war when compiling:

<plugin>     <artifactId>maven-war-plugin</artifactId>     <configuration>         <attachClasses>true</attachClasses>         <webXml>target/web.xml</webXml>         <webResources>             <resource>                 <directory>src/main/webapp</directory>                 <filtering>true</filtering>             </resource>         </webResources>     </configuration> </plugin> 
like image 173
Sergio Gragera Avatar answered Sep 20 '22 15:09

Sergio Gragera


Try running clean install or clean package maven command.

Project > run as > run config > maven build in left panel > right click > new > goal > clean install > base directory> select your current project workspace.> apply> run

same way for clean package or any other maven command.

if it gives BUILD SUCCESS then fine otherwise put that error code here in the question.

like image 29
R Dhaval Avatar answered Sep 21 '22 15:09

R Dhaval