【问题标题】:Maven Servlet Dependency For Wildfly 19.1.0Wildfly 19.1.0 的 Maven Servlet 依赖项
【发布时间】:2020-10-13 17:12:21
【问题描述】:

我在 Eclipse 中构建了一个小型“动态 Web 项目”,并已成功使用它来打包 .WAR 文件并将其部署到 Wildfly 19.1.0 服务器。为此,我使用 Eclipse 将 Wildfly 服务器的上下文添加到项目中。

现在我正在尝试使用 Apache Maven 来打包 .WAR 文件。我认为 Wildfly BOM 是依赖上下文的来源,我可以使用 BOM 来获取 DMR 依赖以停止抛出错误。但是,我有一堆错误,类似于:package javax.servlet 不存在javax.servlet.annotation 不存在。所以我需要知道如何将 servlet 依赖项添加到我的 pom.xml

我的.POM文件如下:

<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>MyToy</groupId>
  <artifactId>MyToy</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>MyToyApp</name>
  
  <dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.wildfly.bom</groupId>
      <artifactId>wildfly-jakartaee8-with-tools</artifactId>
      <scope>import</scope>
      <type>pom</type>
      <version>19.1.0.Final</version>
    </dependency>
  </dependencies>
  </dependencyManagement>
  
  <dependencies>
    <dependency>
      <groupId>jakarta.enterprise</groupId>
      <artifactId>jakarta.enterprise.cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>
  
    <dependency>
      <groupId>org.jboss</groupId>
      <artifactId>jboss-dmr</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.20</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

有人知道我需要添加什么才能使 servlet 正常工作吗?

我不清楚我可以添加到 pom.xml 的依赖项列表在哪里,当我添加 BOM 时我不需要版本。我已经尝试为这些找到一个列表,所以如果它存在,那将是有帮助的。

除了 pom.xml 之外,我也没有其他 Maven 设置,所以如果我遗漏了一个有助于了解的步骤。

【问题讨论】:

  • 谢谢,这是一个很大的帮助。我花了一段时间才意识到我也需要 jboss-parent,它需要比 yum 提供的更新版本的 mvn。不确定此处的协议,但如果您将其放入答案中,我会将其标记为正确以将其关闭。

标签: java maven wildfly java-ee-8


【解决方案1】:

在 maven pom 文件中,您未能定义如下所述的依赖关系,

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet-version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>${servlet-jsp-version}</version>
        <scope>provided</scope>
    </dependency>    
</dependencies>

【讨论】:

    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    相关资源
    最近更新 更多