【问题标题】:Problems with servlets and mavenservlet 和 maven 的问题
【发布时间】:2011-08-02 18:09:08
【问题描述】:

我正在尝试使用 maven 构建我的第一个 servlet,但不知道应该向 POM 添加什么以便 servlet

我尝试将以下依赖项添加到 POM 文件中(我在其中一篇文章中找到)。添加使我能够编译我的 servlet,但是当我尝试运行 mvn 包或测试我的 JUnit 时,我得到了 ClassFormatError:

Initial SessionFactory creation failed.java.lang.ClassFormatError: 
Absent Code attribute in method that is not native or abstract 
in class file javax/validation/Validation

pom.xml 是:

<dependency>
  <groupId>javax</groupId>
  <artifactId>javaee-web-api</artifactId>
  <version>6.0</version>
  <scope>provided</scope>
</dependency>

<repository>
  <id>java.net2</id>
  <name>Repository hosting the Java EE 6 artifacts</name>
  <url>http://download.java.net/maven/2</url>
</repository>

有人可以解释和指导吗?

谢谢 :-)

【问题讨论】:

标签: servlets jakarta-ee maven dependencies pom.xml


【解决方案1】:

首先,您可能需要关注上面 Senthil 的评论。

至于报错,是因为指定的依赖只有API(方法定义),没有实现。

通常,实现由应用服务器提供。因此,应用程序应该在实现 Java EE 6(如 Glassfish)的应用服务器中运行。

mvn package 不应给出任何错误 - 打包前的 test 阶段失败,如果有兴趣使用 mvn package -DskipTests,您可以绕过它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 2013-02-28
    • 2013-10-15
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    相关资源
    最近更新 更多