Apache Tomcat Maven Plugin
  1. Apache Tomcat Maven Plugin
  2. MTOMCAT-119

tomcat7:run-war fails because it expects META-INF\context.xml

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta-1
    • Fix Version/s: 2.1
    • Component/s: tomcat7
    • Labels:
      None

      Description

      run-war and run-war-only goals fail on tomcat7 plugin, looking for the file =META-INF\context.xml=

      How to reproduce:

      • Use the archetype to create a project
        mvn archetype:generate -DarchetypeGroupId=org.apache.tomcat.maven -DarchetypeArtifactId=tomcat-maven-archetype -DarchetypeVersion=2.0-beta-1
      • Build it
      • cd basic-webapp
      • mvn org.apache.tomcat.maven:tomcat6-maven-plugin:run-war
        => works fine
      • mvn org.apache.tomcat.maven:tomcat7-maven-plugin:run
        => works fine
      • mvn org.apache.tomcat.maven:tomcat7-maven-plugin:run-war
        -> kaboom
        [INFO] --- tomcat7-maven-plugin:2.0-beta-1:run-war (default-cli) @ basic-webapp ---
        [INFO] Running war on http://localhost:9090/
        [INFO] Using existing Tomcat server configuration at C:\Users\SAMUEL~1.LAN\AppData\Local\Temp\com.antelink.toto\basic-webapp\target\tomcat
        févr. 16, 2012 6:56:24 PM org.apache.coyote.AbstractProtocol init
        Infos: Initializing ProtocolHandler ["http-bio-9090"]
        févr. 16, 2012 6:56:24 PM org.apache.catalina.core.StandardService startInternal
        Infos: Starting service Tomcat
        févr. 16, 2012 6:56:24 PM org.apache.catalina.core.StandardEngine startInternal
        Infos: Starting Servlet Engine: Apache Tomcat/7.0.25
        févr. 16, 2012 6:56:24 PM org.apache.catalina.startup.ContextConfig processContextConfig
        Grave: Missing context.xml: file:/C:/Users/SAMUEL~1.LAN/AppData/Local/Temp/com.antelink.toto/basic-webapp/target/basic-webapp-1.0-SNAPSHOT/META-INF/context.xml
        java.io.FileNotFoundException: C:\Users\SAMUEL~1.LAN\AppData\Local\Temp\com.antelink.toto\basic-webapp\target\basic-webapp-1.0-SNAPSHOT\META-INF\context.xml (Le fichier spécifié est introuvable)
                at java.io.FileInputStream.open(Native Method)
                at java.io.FileInputStream.<init>(FileInputStream.java:138)
                at java.io.FileInputStream.<init>(FileInputStream.java:97)
                at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
                at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
                at java.net.URL.openStream(URL.java:1035)
                at org.apache.catalina.startup.ContextConfig.processContextConfig(ContextConfig.java:565)
                at org.apache.catalina.startup.ContextConfig.contextConfig(ContextConfig.java:546)
                at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:784)
                at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:318)
                at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
                at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
                at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:401)
                at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
        
      1. web_service_tutorial.zip
        15 kB
        Glen Mazza
      2. MTOMCAT119.patch
        4 kB
        Glen Mazza

        Activity

        Hide
        Nick Lloyd added a comment -

        The reason for this is actually in org.apache.catalina.startup.ContextConfig processContextConfig implementation for tomcat 7, which is different from tomcat 6. Digging into that code shows in tomcat 6 some careful "does this file exist?" checks before any xml stream parsing happens. In tomcat 7 an InputSource is created against the file without checking for the file's existence (which is allowed). After that an attempt is made to create a stream from that InputSource, which fails, but moving forward from that the method only checks for the presence/absence of the InputSource instance instead of whether or not the stream was created successfully.

        Whether this is a bug in tomcat 7 or not I do not know.

        Show
        Nick Lloyd added a comment - The reason for this is actually in org.apache.catalina.startup.ContextConfig processContextConfig implementation for tomcat 7, which is different from tomcat 6. Digging into that code shows in tomcat 6 some careful "does this file exist?" checks before any xml stream parsing happens. In tomcat 7 an InputSource is created against the file without checking for the file's existence (which is allowed). After that an attempt is made to create a stream from that InputSource, which fails, but moving forward from that the method only checks for the presence/absence of the InputSource instance instead of whether or not the stream was created successfully. Whether this is a bug in tomcat 7 or not I do not know.
        Hide
        Glen Mazza added a comment -

        I'm attaching perhaps a simpler example to replicate the matter.

        This attached sample works fine, because in webapps/META-INF I have a context.xml file with this content: <context/>

        To test the sample, from the base root, run:
        mvn clean install tomcat:run-war

        Then check from a browser:
        http://localhost:8080/doubleit/services/doubleit?wsdl
        that you can see a WSDL document (i.e., working).

        If I remove the context.xml file, I get the similar file-not-found exception as the original poster.

        Show
        Glen Mazza added a comment - I'm attaching perhaps a simpler example to replicate the matter. This attached sample works fine, because in webapps/META-INF I have a context.xml file with this content: <context/> To test the sample, from the base root, run: mvn clean install tomcat:run-war Then check from a browser: http://localhost:8080/doubleit/services/doubleit?wsdl that you can see a WSDL document (i.e., working). If I remove the context.xml file, I get the similar file-not-found exception as the original poster.
        Hide
        Glen Mazza added a comment -

        Patch attached. Note one slight potential drawback, is that now both tomcat7:run & tomcat7:run-war will check for the default META-INF/context.xml if contextFile is not explicitly configured (and use that file), however neither will report anything if that file is not present (as it doesn't need to be). In the past only tomcat7:run-war checks for that file if contextFile is not set.

        This patch fixes the exception because now if META-INF/context.xml is not present (and contextFile not explicitly configured for another file), no file is sent to Tomcat and hence the latter will use whatever context defaults it uses. However, if you explicitly configure any file via contextFile that doesn't exist Tomcat will continue to throw a File Not Found exception (as it should), alerting the developer to the problem.

        Unrelated issue fixed, in AbstractRunWarMojo the @Parameter property "maven.tomcat.warDirectory" was not defined, making users unable to provide a setting via the CLI -Dmaven.tomcat.warDirectory option (although it is defined in that class' parent AbstractRunMojo, I've found there's no inheritance of individual @Parameter values, just the @Parameter tag itself.)

        Show
        Glen Mazza added a comment - Patch attached. Note one slight potential drawback, is that now both tomcat7:run & tomcat7:run-war will check for the default META-INF/context.xml if contextFile is not explicitly configured (and use that file), however neither will report anything if that file is not present (as it doesn't need to be). In the past only tomcat7:run-war checks for that file if contextFile is not set. This patch fixes the exception because now if META-INF/context.xml is not present (and contextFile not explicitly configured for another file), no file is sent to Tomcat and hence the latter will use whatever context defaults it uses. However, if you explicitly configure any file via contextFile that doesn't exist Tomcat will continue to throw a File Not Found exception (as it should), alerting the developer to the problem. Unrelated issue fixed, in AbstractRunWarMojo the @Parameter property "maven.tomcat.warDirectory" was not defined, making users unable to provide a setting via the CLI -Dmaven.tomcat.warDirectory option (although it is defined in that class' parent AbstractRunMojo, I've found there's no inheritance of individual @Parameter values, just the @Parameter tag itself.)
        Hide
        Olivier Lamy (*$^¨%`£) added a comment -
        Show
        Olivier Lamy (*$^¨%`£) added a comment - fixed http://svn.apache.org/r1432054 Thanks !
        Hide
        Hudson added a comment -

        Integrated in TomcatMavenPlugin-mvn3.x #227 (See https://builds.apache.org/job/TomcatMavenPlugin-mvn3.x/227/)
        MTOMCAT-119 tomcat7:run-war fails because it expects META-INF\context.xml
        Submitted by Glen Mazza (Revision 1432054)

        Result = SUCCESS
        olamy : http://svn.apache.org/viewvc/?view=rev&rev=1432054
        Files :

        • /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
        • /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunWarMojo.java
        Show
        Hudson added a comment - Integrated in TomcatMavenPlugin-mvn3.x #227 (See https://builds.apache.org/job/TomcatMavenPlugin-mvn3.x/227/ ) MTOMCAT-119 tomcat7:run-war fails because it expects META-INF\context.xml Submitted by Glen Mazza (Revision 1432054) Result = SUCCESS olamy : http://svn.apache.org/viewvc/?view=rev&rev=1432054 Files : /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunWarMojo.java

          People

          • Assignee:
            Olivier Lamy (*$^¨%`£)
            Reporter:
            Antelink
          • Votes:
            5 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development