gpt4 book ai didi

maven - jetty Maven 插件 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-28 22:53:32 25 4
gpt4 key购买 nike

我创建了带有两个 Maven 子模块的 Maven 父模块。它是 war 输出中基于 Web 的应用程序,部署到 Tomcat 目录。问题是为了测试 war 文件,我必须启动 Tomcat 并测试该应用程序。对于这种情况,我决定在父 POM.xml 文件中使用 jetty maven 插件。这是它的样子:

<modules>
<module>hellojavaworld</module>
<module>application</module>
</modules>




<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>


<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/hellojavaworld</contextPath>
</webApp>
<war>c:\apache-tomcat-7.0.64\webapps\hellojavaworld.war</war>
</configuration>
</plugin>

如果我手动启动 Tomcat 并使用 http://localhost:8080/hellojavaworld它工作正常。另一方面使用时

mvn jetty:run-war

它可以工作,但遇到错误:

HTTP ERROR 500
Problem accessing /hellojavaworld/HelloServlet. Reason:

Server Error

Caused by:
java.lang.NoClassDefFoundError: org/apache/log4j/Level

我知道这个问题很常见,因为缺少 jars。我知道这些 jar 放在 c:\apache-tomcat-7.0.64\lib\文件夹中。

所以问题是如何告诉 jetty 使用这个文件夹作为我的 war 文件的外部 jars?

Note: for the Tomcat itself it runs,there is just problem with jetty.

最佳答案

Jetty 不使用 log4j。

为什么您希望 Web 容器在 servlet 规范之外提供您的 WebApp 日志记录?

See the various ServletContext.log() methods for actual servlet spec logging

建议:将你的 log4j jar 文件放在你的 webapp 的 WEB-INF/lib/

关于maven - jetty Maven 插件 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33373506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com