2
votes

I am trying to setup maven to deploy my application to Tomcat for different environments. Everything works when I deploy to localhost, but when trying to deploy to a development server, it fails to deploy. However if I tell the tomcat7-maven-plugin not to deploy the context.xml file, everything works.

pom.xml

...
<profiles>
    <profile>
        <id>local</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <url>http://localhost:8888/manager/text</url>
                        <username>admin</username>
                        <password>admin</password>
                        <mode>both</mode>
                        <contextFile>${project.build.directory}/${project.build.finalName}/META-INF/local/context.xml</contextFile>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>dve</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <url>http://devserver.mycompany.com:8083/manager/text</url>
                        <username>myusername</username>
                        <password>mypassword</password>
                        <mode>both</mode>
                        <warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
                        <contextFile>${project.build.directory}/${project.build.finalName}/META-INF/dve/context.xml</contextFile>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
...

This is what maven tells me when running mvn tomcat7:redeploy -Pdve:

...
[INFO] Deploying war and context to http://devserver.mycompany:8083/myProject
[DEBUG] No server specified for authentication - using defaults
[INFO] OK - Undeployed application at context path /eDiscovery
[INFO] FAIL - Failed to deploy application at context path /eDiscovery
...

And here is the catalina.out from "devserver"

Jan 10, 2014 1:34:00 PM org.apache.catalina.core.ApplicationContext log
INFO: Manager: install: Installing context configuration at 'file:/C:/Users/MyLocalUserName/git/myProject/target/myProject-0.0.1/META-INF/dve/context.xml' from 'file:/C:/Users/MyLocalUserName/git/myProject/target/myProject-0.0.1.war'
Jan 10, 2014 1:34:00 PM org.apache.catalina.core.ApplicationContext log
INFO: Manager: undeploy: Undeploying web application at '/myProject'
Jan 10, 2014 1:34:01 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/myProject]
java.io.FileNotFoundException: /C:/Users/MyLocalUserName/git/myProject/target/myProject-0.0.1/META-INF/dve/context.xml (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:120)
    at org.apache.catalina.manager.ManagerServlet.copyInternal(ManagerServlet.java:1652)
    at org.apache.catalina.manager.ManagerServlet.copy(ManagerServlet.java:1613)
    at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:843)
    at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:353)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
java.io.FileNotFoundException: /C:/Users/MyLocalUserName/git/myProject/target/myProject-0.0.1.war (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:120)
    at org.apache.catalina.manager.ManagerServlet.copyInternal(ManagerServlet.java:1652)
    at org.apache.catalina.manager.ManagerServlet.copy(ManagerServlet.java:1613)
    at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:848)
    at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:353)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

It looks like the server is trying to load the context.xml file from my local path, that it does not have access to. Does anyone know how to fix this? If I turn off the loading of the context.xml (by changing the mode from both to war in the pom file.) everything works fine and the application loads.

Thanks.

1
Do you see the /C:/Users/MyLocalUserName/git/myProject/target/myProject-0.0.1.war?J.P. Armstrong

1 Answers

0
votes

Sorry not possible due to a Tomcat limitation. The context file must be on the server.