This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Deploy to Tomcat with Maven Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Deploy to Tomcat with Maven" Watch "Deploy to Tomcat with Maven" New topic
Author

Deploy to Tomcat with Maven

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

How could I instruct maven to deploy to local tomcat after building a war?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Do I have to use the maven cargo plugin?? If yes, then how? Any suggestions?
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 423

http://mojo.codehaus.org/tomcat-maven-plugin/deployment.html
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

That was not so informative. It tried that and it did not work. I mean after executing mvn:tomcat deploy nothing happened.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

What does the following mean?



By path, do they mean that it is the path of the war file? I guess yes and the war file that I have is generated under the target folder of my web project. So does that mean I specify the target folder location and it is a folder that normally gets rewirtten when I say mvn clean:deploy....Can anyone throw some lights on this?
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 423

Jothi Shankar Kumar wrote:I mean after executing mvn:tomcat deploy nothing happened.

What does the output of Maven look like?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

It's a war file.
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 423

No, I meant, if you type "mvn tomcat:deploy" into your console, what does the output look like?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

I will run that today at home and paste the result here.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Here it is,

[INFO] Webapp assembled in[125 msecs]
[INFO] Building war: D:\My Projects\MyWebApp\web\targ
et\MyWeb.war
[INFO] [tomcat:deploy {execution: default-cli}]
[INFO] Deploying war to http://localhost:8080/web
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot invoke Tomcat manager

Embedded error: Connection refused: connect
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9 seconds
[INFO] Finished at: Mon Nov 23 21:46:41 CET 2009
[INFO] Final Memory: 19M/35M
[INFO] ------------------------------------------------------------------------
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Do I have to start tomcat before I execute this maven goal?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

I did start tomcat and it worked. Now I'm trying to get that done using IntelliJ. Will post if I hit any problems.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Allright that seems to work as well. But it seems to not pick the correct war file. I do not know from where it places the web.war. My war file is actually MyWeb.war. Here is what I have for the build configuration.



The above mentioned entry isin the parent pom of the web project. The pom in my web project has the following entry,

Thomas Hatley
Greenhorn

Joined: Aug 29, 2004
Posts: 2
Greetings Jothi -

Not sure if you're still having issues with this, but if you're doing a standard build/package where the war is being put into the <project_home>/target folder, I'd suggest removing the optional <warFile> element and allowing the tomcat-plugin to use the default settings. This seems to work quite well for me, using a mvn clean tomcat:redeploy will build and push up the new war. Which reminds me, using the 'clean' goal prior to any build is a good practice to get into, as it assures that you're getting the freshest bits.

My current configuration is:


Keep in mind that by default the tomcat-plugin will expect your manager login to be "admin' "<blank>", in other words the user is 'admin' and there is no password set....these are configured in the <tomcat_home>/conf/tomcat-users.xml file.

Hope this helps someone!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deploy to Tomcat with Maven
 
Similar Threads
Deploying a web application to Tomcat 6 through Eclipse Ganymede is not copying the .class files
Hot Deployment in IntelliJ and Tomcat
Make script to install war files in Tomcat
Tomcat plugin
Deploy Java Application On Customer Side?