Maven Servlet Dependency For Wildfly 19.1.0



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

现在我正在尝试使用 Apache Maven 来打包 .战争文件。我认为 Wildfly BOM 是依赖项上下文的来源,我可以使用 BOM 来获取 DMR 依赖项以停止抛出错误。但是,我有一堆错误,内容如下:包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设置,所以如果我错过了一个步骤,那么了解也会有所帮助。

在 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>

最新更新