Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Building WAR file with Maven

 
John Jenson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Jenson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
John Jenson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic