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

I am developing a web application with the Java and Maven build system, and the web server is Tomcat 7.0.12. After packing the entire project into a WAR file in the \ target directory from the Maven build command, I have to copy it to the webapps folder of Tomcat home in order to run it. This is very inconvenient, especially when I modified some source files, because I have to do all this (build, copy to Tomcat, run it). I studied some articles about Maven, Tomcat, Eclipse on this issue, but there is no result. Could you help me: 1. How to get Tomcat to run the WAR file in the target directory of the project, which is directly created by the Maven team? No need to copy / paste the WAR file and restart Tomcat? 2. How to configure Tomcat to debug a web application on Eclipse? Thank you very much!

By the way, I read and tried many times to configure Tomcat, Maven and pom files. But I don’t know what kind of configuration, because there are so many tips! Could you provide a specific configuration example for me? Here are my configuration files:

Tomcat tomcat-users.xml

<role rolename="manager-gui"/> <user username="admin" password="" roles="manager-gui"/> **<role rolename="manager"/> <user username="admin" password="" roles="manager"/>** <role rolename="admin-gui"/> <user username="admin" password="" roles="admin-gui"/> 

Maven.xml Settings

Cat admin

And the project pom.xml file:

 <build> <finalName>my-project</finalName> <defaultGoal>package</defaultGoal> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <version>1.1</version> <configuration> <server>tomcat</server> <warFile> ${project.build.directory}/${project.build.finalName}.war</warFile> </configuration> </plugin> </plugins> // Other plugins </build> 

Details: If I started mvn tomcat: deploy before starting the Tomcat instance, the returned error is: "Unable to call the Tomcat manager: Connection failed: connect." Otherwise, if the Tomcat instance was started before calling mvn tomcat: deploy, the error is: "Unable to call the Tomcat manager: the server returned an HTTP: 403 response code for the URL: http: // localhost: 8080 / manager / deploy? Path =% 2Fmy -project & war = ... "

+6
source share
2 answers

There are several ways to do this.

The Tomcat maven plugin http://mojo.codehaus.org/tomcat-maven-plugin/ provides you with a way to deploy directly to tomcat from maven. First you had to set up your tomcat users. For more information on setting up users, see http://tomcat.apache.org/tomcat-7.0-doc/config/realm.html .

For debugging, you can run tomcat with the arguments specified at http://wiki.apache.org/tomcat/FAQ/Developing

Another way is to configure tomcat to point to your war. See http://tomcat.apache.org/tomcat-7.0-doc/config/context.html , specifically the docbase parameter.

EDIT 1 Based on the revised question http 403 forbidden, this means that you did not authenticate correctly.

Modify your tomcat-users.xml to look like this:

You need to add the username / password link in pom.xml. Your settings.xml should contain (based on your configuration)

 <server> <id>tomcat</id> <username>admin</username> <password></password> </server> 

Theres a nice page http://www.avajava.com/tutorials/lessons/how-do-i-deploy-a-maven-web-application-to-tomcat.html that explains this more fully. However, the information may be outdated.

+4
source

I ran into the same problem.

I assume this is the eclipse-tomcat plugin that does this. And I have no idea why this works differently in tomcat 7, the opposite of tomcat 6, with which I had no problems.

Anyway, I did this to create maven in the directory / web -app / WEB-INF

 <build> <directory>${basedir}/src/main/webapp/WEB-INF</directory> ... </build> 

After this configuration, eclipse: eclipse should provide the project / classpath eclipse files. Resources: shoudl resources also work accordingly.

+2
source

Source: https://habr.com/ru/post/886051/


All Articles