0
votes

Error occurred when run an java-thymeleaf-maven-spring application

Here am using tomcat7.

Here show steps

  1. Download project from git-hub

  2. mvn clean install shows Build Success

  3. mvn tomcat:deploy Build Failure

and shows error

[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (default-cli) on project spring-mvc-thymeleaf: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2Fspring-mvc-thymeleaf&war= -> [Help 1]

Here download many programs all of them shows this problem

the one of the programs pom.xml file show here

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>net.exacode.bootstrap</groupId>
    <artifactId>spring-mvc-thymeleaf</artifactId>
    <packaging>war</packaging>
    <name>spring-mvc-thymeleaf</name>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <!-- Dependency version -->
        <spring.version>3.1.0.RELEASE</spring.version>
        <slf4j.version>1.6.4</slf4j.version>
        <!-- Spring profile -->
        <spring.profiles.active>development</spring.profiles.active>
    </properties>

    <dependencies>
        <!-- Logging dependencies -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring3</artifactId>
            <version>2.0.13</version>
        </dependency>
        <!-- Spring dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.3.1.Final</version>
        </dependency>
        <dependency>
            <groupId>nz.net.ultraq.web.thymeleaf</groupId>
            <artifactId>thymeleaf-layout-dialect</artifactId>
            <version>1.0.5</version>
        </dependency>
        <!--We need servlet API for compiling the classes. Not needed in runtime -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
</project>

and the link of the program https://github.com/mendlik/spring-mvc-thymeleaf

I search with this error on google but I can't find any problem with programs side.

tomcat users file shows,

<role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
1

1 Answers

1
votes

Have you included maven tomcat plugin in your pom.xml? build section of your pom shoul be like :

<build>
   <resources>
      <resource>
          <directory>src/main/resources</directory>
          <filtering>true</filtering>
          </resource>
   </resources>
   <plugins>
      <!-- Maven Tomcat Plugin -->
      <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
    <configuration>
        <url>http://127.0.0.1:8080/manager</url>
        <server>TomcatServer</server>
        <path>/mkyongWebApp</path>
    </configuration>
       </plugin>
    <plugins>
</build>

You also have to add an user with administrator access right for Tomcat. Edit the file – “%TOMCAT_PATH%/conf/tomcat-users.xml“ and add role manager for user tomcat.

<role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager"/>
  <user username="tomcat" password="tomcat" roles="tomcat,manager"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>