gpt4 book ai didi

java - Struts 2.5.5 中的 Maven 依赖和 Tomcat 异常

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

我的环境配置有问题。我正在使用 Eclipse neon.1、Tomcat 8.5、Java 版本 1.8.0_77,我正在尝试使用 Struts 2.5.5 创建一个简单的 Hello World。

如果我手动将 Struts 2.5.5 JAR 添加到 WEB-INF/lib 文件夹,一切正常,但如果我通过 Maven 添加 Struts 依赖项,当我在服务器上运行我的项目时,Tomcat 会启动索引超出范围异常。

此问题仅出现在最新版本的 Struts (2.5.5) 中。事实上,如果我将 struts2-core 2.3.31 添加到 pom.xml(而不是 2.5.5),一切正常。

我已经尝试过使用 Tomcat 7、Tomcat 8 和 Eclipse Mars。

我创建了一个动态 Web 项目,然后将其转换为 Maven 项目;我也直接创建了一个Maven项目,但是问题依旧。

有解决问题的办法吗?

编辑:我在 .metadata 文件夹的 .log 文件中找到了异常的整个堆栈跟踪。

!ENTRY org.eclipse.wst.server.core 4 0 2016-12-01 19:21:09.917
!MESSAGE Could not publish to the server.
!STACK 0
java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(BufferedInputStream.java:338)
at org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsByteArray(Util.java:500)
at org.eclipse.jdt.core.ToolFactory.createDefaultClassFileReader(ToolFactory.java:311)
at org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities.isEJBArchive(JavaEEArchiveUtilities.java:909)
at org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities.refineForJavaEE(JavaEEArchiveUtilities.java:615)
at org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities.openArchive(JavaEEArchiveUtilities.java:377)
at org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities.openBinaryArchive(JavaEEArchiveUtilities.java:297)
at org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper$ArchiveCache.openArchive(JavaEEBinaryComponentHelper.java:612)
at org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper.openArchive(JavaEEBinaryComponentHelper.java:470)
at org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper.getUniqueArchive(JavaEEBinaryComponentHelper.java:422)
at org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper.getArchive(JavaEEBinaryComponentHelper.java:415)
at org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper.getJavaEEQuickPeek(JavaEEBinaryComponentHelper.java:98)
at org.eclipse.jst.j2ee.project.JavaEEProjectUtilities.getJ2EEComponentType(JavaEEProjectUtilities.java:273)
at org.eclipse.jst.j2ee.internal.common.exportmodel.JEEHeirarchyExportParticipant.isChildModule(JEEHeirarchyExportParticipant.java:42)
at org.eclipse.wst.common.componentcore.internal.flat.GlobalHeirarchyParticipant.isChildModule(GlobalHeirarchyParticipant.java:41)
at org.eclipse.wst.common.componentcore.internal.flat.FlatVirtualComponent.isChildModule(FlatVirtualComponent.java:367)
at org.eclipse.wst.common.componentcore.internal.flat.FlatVirtualComponent.addUsedReferences(FlatVirtualComponent.java:305)
at org.eclipse.wst.common.componentcore.internal.flat.FlatVirtualComponent.treeWalk(FlatVirtualComponent.java:235)
at org.eclipse.wst.common.componentcore.internal.flat.FlatVirtualComponent.cacheResources(FlatVirtualComponent.java:188)
at org.eclipse.wst.common.componentcore.internal.flat.FlatVirtualComponent.fetchResources(FlatVirtualComponent.java:118)
at org.eclipse.wst.web.internal.deployables.FlatComponentDeployable.members(FlatComponentDeployable.java:227)
at org.eclipse.jst.j2ee.internal.deployables.J2EEFlexProjDeployable.members(J2EEFlexProjDeployable.java:267)
at org.eclipse.wst.server.core.internal.ModulePublishInfo.fillCache(ModulePublishInfo.java:314)
at org.eclipse.wst.server.core.internal.ModulePublishInfo.getDelta(ModulePublishInfo.java:396)
at org.eclipse.wst.server.core.internal.ServerPublishInfo.getDelta(ServerPublishInfo.java:366)
at org.eclipse.wst.server.core.internal.Server.getPublishedResourceDelta(Server.java:1578)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.getPublishedResourceDelta(ServerBehaviourDelegate.java:698)
at org.eclipse.jst.server.tomcat.core.internal.TomcatServerBehaviour.getPublishedResourceDelta(TomcatServerBehaviour.java:958)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.computeDelta(ServerBehaviourDelegate.java:874)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:909)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:774)
at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3172)
at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:345)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

这是我的 pom.xml

<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>basic_struts</groupId>
<artifactId>basic_struts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.5</version>
</dependency>
</dependencies>

<build>
<finalName>basic_struts</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>

最佳答案

经过多日的研究,我明白了如何解决这个问题,现在我告诉你如何去做。

  1. 关闭 Eclipse;
  2. 删除 C:\Users[用户名].m2\repository 的内容(如果您是使用 Windows)或 ~/.m2/repository(如果您使用的是 macOS);
  3. 重新打开 Eclipse,右键单击项目,选择“Maven”、“更新”项目...”,选中“强制更新快照/版本”,然后点击“确定”。
  4. 在 Tomcat 服务器上运行您的项目:它现在应该可以工作了!

我希望这个迷你指南可以帮助那些遇到同样问题的人。

关于java - Struts 2.5.5 中的 Maven 依赖和 Tomcat 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40868599/

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