【发布时间】:2018-05-22 14:32:20
【问题描述】:
我已经在 Eclipse 中使用 maven 开发 Java (Java 8) Web 应用程序一年了。我从项目开始就创建了这个 webapp 并使用 Maven v 3.5。我通常将我的 Web 应用程序部署在 tomcat 8.5 服务器上('Run as => run on server')。
我一直使用我的 pom.xml 管理我的依赖项,防止使用 Eclipse 中的 hte 构建路径配置菜单做奇怪的事情。
问题从昨天开始:我添加了一个来自我之前制作和安装的其他 java/maven 项目的依赖项,并在我的 pom.xml 中添加了这些行:
<dependency>
<groupId>tlnPdf</groupId>
<artifactId>tlnPdf</artifactId>
<version>1.0</version>
</dependency>
当我添加来自其他项目的新依赖项时,我的 Eclipse 有时会这样做,我在部署 webapp 时遇到问题,一些关于我的其他项目的 pom.properties 的消息(抱歉,我不记得了)。在这种情况下,和往常一样,我只需要关闭我的 webapp 项目,从命令提示符启动mvn eclipse:clean,然后重新打开我的项目;问题就消失了。
Eclipse 不会在从包含的新依赖项中导入类的类上显示问题。
我的 web 应用程序开头的一个类上还有一个监听器,在我的 web.xml 上声明:
<listener>
<listener-class>com.package.InitTomcat</listener-class>
</listener>
这个监听器是功能性的,我最后没有修改它。
但是昨天出现了一个新问题;当我想在我的服务器上部署我的 webapp 时,我收到了很多这样的警告:
org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [...] to the cache because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache。然后,一个错误告诉我 InitTomcat 类不存在:
java.lang.ClassNotFoundException: com.package.InitTomcat
所以,首先我认为缓存警告导致了这个问题。我做了this stackoverflow post 解释的事情,警告消失了;但不是错误。
在 Eclipse 之外,在命令提示符下,我尝试编译我的项目并使用 mvn clean install 获取我的 app.war 文件。编译没有显示任何错误,战争是正确的。我在 tomcat 上手动部署了我的战争,但没有出现任何问题。
因此,我查看了两个部署目录(一个来自 eclipse,另一个来自我的 app.war 手动),我在部署的存储库树上看到了一些奇怪的东西:
在部署良好的 webapp(来自 app.war)上,我有类似的东西:
|*some directories and files
|*META-INF
|*WEB-INF
|*classes
|com (etc...)
|*lib
|web.xml
在从 eclipse 部署的 webapp 中:
*some directories and files
*META-INF
*WEB-INF
|*classes
|*.settings (why the hell does this directory are here ?)
|*bin
|*.settings
|*src
|*target
|*classes
|*com ect... (my .class files are here !!)
|*generated-sources
|*m2e-wtp
|*maven-archiver
|*maven-status
|*myapp (this directory have the same content as the "good web app deployed")
|*test-classes
|*WebContent
|*temp
|*webContent
|pom.xml
|.project
|*src
|*target
|*temp
|*WebContent
|*...
|*lib
|web.xml
“好的”webapp 大小为 275Mb,另一个为 865Mb
我怀疑这个问题发生在 eclipse 部署我的网络应用程序时,它解释了它找不到 InitTomcat 类,因为它似乎在错误的位置。但我不知道为什么它现在决定这样做。
我尝试从 Eclipse 中删除项目、清理 Eclipse 等...但没有结果。我尝试了 3 个不同版本的 tomcat:8.5.14、8.2.23 和 9.0.2,总是具有相同的行为
郁闷中,我下载了最后一个版本的eclipse,用maven把我的webapp项目导入进去;但结果是一样的。
最后,我的问题很简单:有没有人知道它正在发生什么,以及如何解决它?提前致谢!
【问题讨论】: