2

Вот мой pom.xml файл:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.skorodielov.yurii</groupId>
    <artifactId>servlet</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.0-b07</version>
        </dependency>

    </dependencies>

</project>

При сборке проекта в Intellij IDEA падает ошибка и вот полный стек трэйс:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building servlet 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ servlet ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ servlet ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\Skorodielov\IdeaProjects\servlet\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ servlet ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Skorodielov\IdeaProjects\servlet\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ servlet ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ servlet ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ servlet ---
[INFO] Packaging webapp
[INFO] Assembling webapp [servlet] in [C:\Users\Skorodielov\IdeaProjects\servlet\target\servlet-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [62 msecs]
[INFO] Building war: C:\Users\Skorodielov\IdeaProjects\servlet\target\servlet-1.0-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.299 s
[INFO] Finished at: 2018-06-07T18:29:19+03:00
[INFO] Final Memory: 16M/141M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project servlet: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1

Перешёл по ссылке в описании ошибки, но что-то ничего не понял... Подскажите в чём проблема и как я её могу устранить ?

Файл web.xml:

<web-app >
    <display-name>Simple Servlet Application</display-name>
    <servlet>
        <servlet-name>simpleServlet</servlet-name>
        <servlet-class>MyServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>simpleServlet</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
</web-app>
0

2 ответа 2

0

Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

Добавьте это свойство плагина, чтобы починить проблему

<failOnMissingWebXml>false</failOnMissingWebXml>

Более подробно об этом можно прочитать здесь.

6
  • Roman C, добавлять в dependencies или после <packaging>war</packaging> ?
    – YuriiS
    7 июн 2018 в 17:28
  • Добавил в ответ ссылку.
    – Roman C
    7 июн 2018 в 17:31
  • у меня в проекте есть файл web.xml
    – YuriiS
    7 июн 2018 в 17:34
  • 1
    зачем тогда у вас servlet-api 4.0?
    – Roman C
    7 июн 2018 в 17:50
  • Roman C, если честно, то не знаю... так было в уроке, вот пытаюсь разобраться с этим сам
    – YuriiS
    7 июн 2018 в 19:11
0

Проблема решилась после переноса папки webapp, в которой лежал файл web.xml из корневого каталога, в папку main, которая находится в папке src.

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.