Question

I want to deploy my app to an embedded tomcat in the pre-integration-test phase.

However, I have a very particular requirement: I depend on a webapp that is not mavenised. THe effort to mavenise it is bigger than I can afford, so I thought a good solution would be to deploy the war for my dependency and then deploy my application war.

My plugin configuration looks like this:

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <path>/spr</path>
            <url>http://localhost:8080/manager/text</url>
            <server>localServer</server>
            <additionalConfigFilesDir>${additionalFilePath}</additionalConfigFilesDir>
            <tomcatUsers>${somePath}/tomcat-users.xml</tomcatUsers>
            <fork>true</fork>
        </configuration>
        <executions>
            <execution>
                <id>start-portal</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>run-war</goal>
                </goals>
                <configuration>
                    <path>/</path>
                    <warDirectory>${my.dependency.war.path}</warDirectory>
                </configuration>
            </execution>
            <execution>
                <id>deploy-spr</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>deploy</goal>
                </goals>
                <configuration>
                    <path>/spr</path>
                </configuration>
            </execution>
            <execution>
                <id>stop-tomcat</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>shutdown</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

The server is started successfully by my start-portal execution and the dependency is correctly deployed.

The problem is with execution deploy-spr. I keep getting the error:

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy-only (deploy-spr) on project spr: Tomcat return http status error: 403, Reason Phrase: Forbidden: <html><head><title>Apache Tomcat/7.0.47 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 403 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>Access to the specified resource has been forbidden.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.47</h3></body></html> -> [Help 1]

For completeness, my settings.xml has:

<server>
  <id>localServer</id>
  <username>tomcatScript</username>
  <password>password</password>
</server>

And my tomcat-users.xml, which is referenced by my pom file has:

<tomcat-users>

    <!-- Role to manage WAR files via HTML /manager. The name should be as is! -->
    <role rolename="manager-gui"/>
    <!-- Role to manage WAR files via script like Maven. The name should be as is! -->
    <role rolename="manager-script"/>

    <!-- One user cannot have manager-gui and manager-script roles -->
    <user username="tomcat" password="password" roles="manager-gui"/>
    <user username="tomcatScript" password="password" roles="manager-script"/>

</tomcat-users>

I found several similar errors, such as the one described here. However, it's not exactly the same, since all these posts consider the server to be already running.

I did a test to try to deploy the application to an already running tomcat and it works. The problem is really having maven start an embedded tomcat and deploy to that embedded tomcat.

Right now, I consider the problem might be:

  • tomcat-users.xml specified in pom.xml is not properly read for some reason.
  • maven is not handling well having two executions in pre-integration-test phase (although I already forced the start of the server in package phase and it still doesn't work).

By the way, the reason why I'm doing it in two different executions in the same phase is pretty much because I was not able to configure start-portal to deploy two webapps at once (one from a maven artifact and another from an external war). If anyone knows how to do this, that would be an acceptable fix for me too (although not really related with the title of this question). The webapps config property doesn't seem to work with external wars, just maven artifacts.

I'm completely out of ideas. Anyone ever ran into this problem or has some idea how I can accomplish this?

Thanks

Was it helpful?

Solution

I managed to solve the problem and it's actually pretty simple.

Since no one answered, here's what I did. I only have one execution now to deploy both apps.

<execution>
 <id>start-portal</id>
     <goal>run-war</goal>
 </goals>
 <configuration>
     <path>/</path>
     <fork>true</fork>
     <warDirectory>${portal.war}</warDirectory>
     <additionalConfigFilesDir>${portal.properties}</additionalConfigFilesDir>
     <webapps>
         <webapp>
             <contextPath>/spr</contextPath>
         </webapp>
     </webapps>
 </configuration>
</execution>

In the webapps section, I specify all the apps I want to deploy from maven artifacts (in my case I only have one and it's the one to which this pom belongs to, so I can omit it).

In the warDirectory I specify my external exploded war. I guess there's a limitation here, since it looks like it's only possible to deploy one single external webapp, but that's enough for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top