File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Building WAR file with Maven Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Building WAR file with Maven " Watch "Building WAR file with Maven " New topic
Author

Building WAR file with Maven

John Jenson
Greenhorn

Joined: Jul 03, 2013
Posts: 8
Hello everyone! I've been struggling with MAVEN for a long time now and I don't know what to do anymore, so I am writing here is desperate need of help. Here is the actual problem: I am creating a java web services ( SOAP) using CXF and eclipse. I know have a dynamic web project that runs on Tomcat 7 and I want to export my web project using Maven into WAR format. I've read so many tutorial and sites, but i still can't manage to create a war package. So, please, someone help me with writing with the pom.xml file. Here is the structure of my Dynamic Webprojet :

I've managed to write some pom.xml files but all of them gave me errors. Can you, please, help me with creating the pom.xml that should generate the war file, so I can deploy it on Tomcat 7. I will be monitoring this thread so I can answer without delay.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

John,
Welcome to CodeRanch!

Maven uses "convention over configuration" and expects your web project to be set up in a certain way. And what you have isn't the way. It's possible - but difficult - to use a different directory structure and Maven doesn't recommend it without a really good reason.

This page show you the "Maven way" directory structure.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
John Jenson
Greenhorn

Joined: Jul 03, 2013
Posts: 8
Thank you for the answer, Jeanne . I tried again but no success...
Allright, i tried again ... I've got the following structure:


I try mvn compile war:war and the following error pops out: Failed to execute goal org.apache.maven.plugis:maven-war-plugin:2.1.1 war. Error assembling WAR: webxml attribute is required ... I dont know whether is should install this plugin or it downloads itself automatically. Also ... I have webxml .. ? Can someone explain ?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

John,
Your directory structure is better, but still not what maven is expecting. It wants web.xml in main/resources/webapp/WEB-INF/web.xml. You left out the webapp folder along the path.

The error means the web.xml isn't where Maven expects it to be so when you fix that, you should be good.
John Jenson
Greenhorn

Joined: Jul 03, 2013
Posts: 8
Hi there, sorry for my delay but I was offline for two days... I tried again with this structure:


The pom.xml file looks like:



I still cant manage to make it generate war file. It gives me the following error ... Failed to execute maven.plugins:maven-war-plugin:2.1.1:war. Error assembling WAR: webxml attribute is required... I have the webxml file. What attribute does it require ?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

I'm sorry. That didn't work because I gave you bad information. It is main/webapp/WEB-INF/web.xml. Which I got from the war plugin doc page
John Jenson
Greenhorn

Joined: Jul 03, 2013
Posts: 8
Well, I still can't manage to generate a war file. It generates me 800kb WAR file. I want later to upload this WAR file to a Tomcat server and use my web services from there ... but I just cant do it. Can someone explain me what should I do, please. If you have any questions you may ask me, too. I am trying with Maven Project on Eclipse and with Dynamic Web Project, too.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

John Jenson wrote:I still can't manage to generate a war file. It generates me 800kb WAR file.

These statements are conflicting, which one is true?

If you want to deploy a generated WAR, you will need to use a Maven plugin to do that. Look at the Tomcat Maven plugin (http://mojo.codehaus.org/tomcat-maven-plugin/) or the Cargo plugin (http://cargo.codehaus.org/Maven2+plugin).


JBoss In Action
John Jenson
Greenhorn

Joined: Jul 03, 2013
Posts: 8
Well, I thought that it should be the same WAR file that eclipse exports( it is about 10 MB). Thanks for the support. Tomorrow I will try these plugins and I hope it would work this time. I suppose that I don't need to install anything just to configure the pom file and maven will take care of the rest by itself. Thank you a lot for all the explanations
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

Have you examined the contents of the WAR file to see what JARs Eclipse provided as compared to what Maven provided? Or to see what the other differences are? If Maven successfully compiled your code then it will have included all JARs listed in your dependencies and all of their dependencies; perhaps you Eclipse project listed more JARs that was needed in the Build Path.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Building WAR file with Maven
 
Similar Threads
Learning Maven
Maven Build Script Problem
Continuous integration - Bamboo, Maven
Make a project be dynamic web project
Creating build using maven in eclipse