Uploaded image for project: 'Maven WAR Plugin'
  1. Maven WAR Plugin
  2. MWAR-396

Check the existence of the web.xml based on the existence of particular classes

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:
      None

      Description

      Based on MWAR-262 we have changed the default to false but the existence of the web.xml should be checked based on the existence of particular classes? But which?

        Activity

        Hide
        gboue Guillaume Boué added a comment -

        It would be possible to check for the presence of javax.servlet.annotation.WebServlet. This annotation was introduced in the Servlet 3.0 API and replaces the <servlet> declaration in the web.xml. So if that class isn't in the compile classpath of the MavenProject being built, a web.xml should be present.

        How about the possible solution? Call mavenProject.getCompileClasspathElements(), create a new URLClassLoader for the paths of that list and use this classloader to determine if that class can be loaded.

        Show
        gboue Guillaume Boué added a comment - It would be possible to check for the presence of javax.servlet.annotation.WebServlet . This annotation was introduced in the Servlet 3.0 API and replaces the <servlet> declaration in the web.xml . So if that class isn't in the compile classpath of the MavenProject being built, a web.xml should be present. How about the possible solution? Call mavenProject.getCompileClasspathElements() , create a new URLClassLoader for the paths of that list and use this classloader to determine if that class can be loaded.
        Hide
        rfscholte Robert Scholte added a comment -

        +1, this is what I had in mind too.

        Show
        rfscholte Robert Scholte added a comment - +1, this is what I had in mind too.
        Hide
        gboue Guillaume Boué added a comment -

        Do we keep this in version 3.0.1 (or 3.1.0 by the way)? Maybe this should be released in 3.0.0 as this constitutes the major version update?

        The current fix I have is not to have a default value for failOnMissingWebXml. This way, if it is explicitly set, we use this one and if it isn't, we don't fail the build when we can determine that the project is running Servlet API >= 3.0.

        Show
        gboue Guillaume Boué added a comment - Do we keep this in version 3.0.1 (or 3.1.0 by the way)? Maybe this should be released in 3.0.0 as this constitutes the major version update? The current fix I have is not to have a default value for failOnMissingWebXml . This way, if it is explicitly set, we use this one and if it isn't, we don't fail the build when we can determine that the project is running Servlet API >= 3.0.
        Hide
        rfscholte Robert Scholte added a comment -

        I tend to agree here since it is quite a different approach to get the value. If you can fix this fast, you could ask Karl Heinz Marbaise to cancel the vote and apply your changes first.

        Show
        rfscholte Robert Scholte added a comment - I tend to agree here since it is quite a different approach to get the value. If you can fix this fast, you could ask Karl Heinz Marbaise to cancel the vote and apply your changes first.
        Hide
        gboue Guillaume Boué added a comment -

        Fixed in r1760101.

        Show
        gboue Guillaume Boué added a comment - Fixed in r1760101 .
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Jenkins build maven-plugins #7213 (See https://builds.apache.org/job/maven-plugins/7213/)
        MWAR-396 Check the existence of the web.xml based on the existence of particular classes

        In 3.0, the default value of 'failOnMissingWebXml' was changed to be 'false'. With this fix, the default value is set to 'null' so that:

        • when the parameter is explicitly specified, it is used;
        • when it is not specified, it defaults to whether or not we can detect a Servlet 3.0 or newer environment for the web application. Such an environment does not need a web.xml since it can be written in Java. (gboue: http://svn.apache.org/viewvc/?view=rev&rev=1760101)
        • (edit) maven-war-plugin/pom.xml
        • (add) maven-war-plugin/src/it/MWAR-396_no-servlet30
        • (add) maven-war-plugin/src/it/MWAR-396_no-servlet30/invoker.properties
        • (add) maven-war-plugin/src/it/MWAR-396_no-servlet30/pom.xml
        • (add) maven-war-plugin/src/it/MWAR-396_servlet30
        • (add) maven-war-plugin/src/it/MWAR-396_servlet30/pom.xml
        • (add) maven-war-plugin/src/it/MWAR-396_servlet30/verify.bsh
        • (edit) maven-war-plugin/src/main/java/org/apache/maven/plugins/war/WarMojo.java
        • (edit) maven-war-plugin/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java
        • (edit) maven-war-plugin/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java
        • (edit) maven-war-plugin/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java
        • (add) maven-war-plugin/src/test/resources/unit/sample_wars/javax.servlet-api-3.0.1.jar
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build maven-plugins #7213 (See https://builds.apache.org/job/maven-plugins/7213/ ) MWAR-396 Check the existence of the web.xml based on the existence of particular classes In 3.0, the default value of 'failOnMissingWebXml' was changed to be 'false'. With this fix, the default value is set to 'null' so that: when the parameter is explicitly specified, it is used; when it is not specified, it defaults to whether or not we can detect a Servlet 3.0 or newer environment for the web application. Such an environment does not need a web.xml since it can be written in Java. (gboue: http://svn.apache.org/viewvc/?view=rev&rev=1760101 ) (edit) maven-war-plugin/pom.xml (add) maven-war-plugin/src/it/ MWAR-396 _no-servlet30 (add) maven-war-plugin/src/it/ MWAR-396 _no-servlet30/invoker.properties (add) maven-war-plugin/src/it/ MWAR-396 _no-servlet30/pom.xml (add) maven-war-plugin/src/it/ MWAR-396 _servlet30 (add) maven-war-plugin/src/it/ MWAR-396 _servlet30/pom.xml (add) maven-war-plugin/src/it/ MWAR-396 _servlet30/verify.bsh (edit) maven-war-plugin/src/main/java/org/apache/maven/plugins/war/WarMojo.java (edit) maven-war-plugin/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java (edit) maven-war-plugin/src/test/java/org/apache/maven/plugins/war/stub/JarArtifactStub.java (edit) maven-war-plugin/src/test/java/org/apache/maven/plugins/war/stub/MavenProjectBasicStub.java (add) maven-war-plugin/src/test/resources/unit/sample_wars/javax.servlet-api-3.0.1.jar

          People

          • Assignee:
            gboue Guillaume Boué
            Reporter:
            khmarbaise Karl Heinz Marbaise
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development