Run WAR file in /target directory of Maven project by Tomcat

I'm developing a web application with Java and Maven build system and the web server is Tomcat 7.0.12. After packaging whole project to a WAR file to \target directory by Maven build command, I have to copy it to the webapps folder of Tomcat home to run it. It's very inconvenient, especially when I modified some source files because I have to do all those things (build, copy to Tomcat, run it) again. I've research some articles about Maven, Tomcat, Eclipse on this problem, but there's no result. Could you please help me: 1. How to make Tomcat run the WAR file on target directory of project which is built by Maven command directly? No need to copy/paste the WAR file and restart Tomcat? 2. How can I configure the Tomcat to debug the web application on Eclipse? Thank you so much!

BTW, I've read and tried to configure Tomcat, Maven and pom file many times. But I don't know what is the exact configuration, because there are so many advices! Could you provide a particular example of configuration for me? Here is my configuration files:

Tomcat tomcat-users.xml

  
  
  **
  **
  
  

Maven settings.xml

tomcat admin

And the pom.xml file of project:


      my-project
      package
      
         
       org.codehaus.mojo
       tomcat-maven-plugin
       1.1
       
          tomcat  
               ${project.build.directory}/${project.build.finalName}.war
       
     
      
   // Other plugins
   

More details: If I run mvn tomcat:deploy before starting a Tomcat instance, the returned error is "Cannot invoke Tomcat manager: Connection refused: connect." Otherwise, if a Tomcat instance has been started before calling mvn tomcat:deploy, the error is "Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2Fmy-project&war=..."

6
задан Đinh Hồng Châu 16 April 2011 в 18:27
поделиться