Java Maven编译以静默方式失败-未解决的编译问题

Java Maven编译以静默方式失败-未解决的编译问题,java,eclipse,maven,Java,Eclipse,Maven,我有一个关于SpringWebApp maven构建的有趣问题。在eclipse内部构建时,一切正常,但在通过maven构建并部署到tomcat 8容器时,webapp在启动时失败,出现以下错误: Caused by: java.lang.NoClassDefFoundError: FilterConfig 现在,我尝试了所有明显的和有良好文档记录的依赖性问题(设置javax.servlet-api和jspapi导入上提供的范围,并确保它们是最新版本,因为这是一个Java8项目)。我已确保所有

我有一个关于SpringWebApp maven构建的有趣问题。在eclipse内部构建时,一切正常,但在通过maven构建并部署到tomcat 8容器时,webapp在启动时失败,出现以下错误:

Caused by: java.lang.NoClassDefFoundError: FilterConfig
现在,我尝试了所有明显的和有良好文档记录的依赖性问题(设置javax.servlet-api和jspapi导入上提供的范围,并确保它们是最新版本,因为这是一个Java8项目)。我已确保所有编译器插件均为最新版本:

maven战争插件 3.1.0

maven编译器插件 3.6.1

但是webapp启动失败,maven构建控制台输出中没有显示错误。在(正在工作的)eclipse构建和神秘失败的maven等价物之间进行了大量令人挠头和艰苦的比较之后,发现maven生成的一些类文件中有描述编译问题的文本。(以下内容是从eclipse中针对.class文件的“Open With>Text Editor”选项中提取出来的-一些字符必须省略,因为它们无法正确复制)

我无法理解maven过程是如何成功完成的,我尝试过的任何mvn目标都没有显示错误

mvn编译器:编译

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xxxx 2.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ EBPP ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ EBPP ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.413 s
[INFO] Finished at: 2017-06-28T15:11:45+01:00
[INFO] Final Memory: 9M/213M
[INFO] ------------------------------------------------------------------------
上面的-x显示了大量调试输出,但没有提示编译问题,事实上,它声明了包含已识别的未解决依赖项的类文件

...
[DEBUG]    javax.servlet:javax.servlet-api:jar:3.1.0:provided  
[DEBUG]    org.apache.velocity:velocity:jar:1.7:compile
[DEBUG]    commons-collections:commons-collections:jar:3.2.1:compile 
[DEBUG]    commons-lang:commons-lang:jar:2.4:compile 
[DEBUG]    javax.servlet.jsp:jsp-api:jar:2.2:provided 
...
mvn依赖关系:构建类路径

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xxxx 2.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:build-classpath (default-cli) @ EBPP ---
[INFO] Dependencies classpath:
C:\Users\xxxxxx\.m2\repository\org\springframework\webflow\spring-webflow\2.4.5.RELEASE\spring-webflow-2.4.5.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\xxxxxx\.m2\repository\opensymphony\ognl\2.6.11\ognl-2.6.11.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\webflow\spring-binding\2.4.5.RELEASE\spring-binding-2.4.5.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\webflow\spring-js\2.4.5.RELEASE\spring-js-2.4.5.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\webflow\spring-js-resources\2.4.5.RELEASE\spring-js-resources-2.4.5.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\spring-beans\4.3.0.RELEASE\spring-beans-4.3.0.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\spring-context\4.3.0.RELEASE\spring-context-4.3.0.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\spring-aop\4.3.0.RELEASE\spring-aop-4.3.0.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\spring-expression\4.3.0.RELEASE\spring-expression-4.3.0.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\spring-web\4.3.0.RELEASE\spring-web-4.3.0.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\spring-webmvc\4.3.0.RELEASE\spring-webmvc-4.3.0.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\spring-core\4.3.9.RELEASE\spring-core-4.3.9.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\com\xxxxxxx\ebpp\JComms\2.0.1\JComms-2.0.1.jar;C:\Users\xxxxxx\.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;C:\Users\xxxxxx\.m2\repository\javax\mail\mail\1.4.7\mail-1.4.7.jar;C:\Users\xxxxxx\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\xxxxxx\.m2\repository\org\apache\httpcomponents\httpclient\4.5.1\httpclient-4.5.1.jar;C:\Users\xxxxxx\.m2\repository\org\apache\httpcomponents\httpcore\4.4.3\httpcore-4.4.3.jar;C:\Users\xxxxxx\.m2\repository\commons-codec\commons-codec\1.9\commons-codec-1.9.jar;C:\Users\xxxxxx\.m2\repository\commons-httpclient\commons-httpclient\3.1\commons-httpclient-3.1.jar;C:\Users\xxxxxx\.m2\repository\com\xxxxxxx\ebpp\JCore\2.0.1\JCore-2.0.1.jar;C:\Users\xxxxxx\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;C:\Users\xxxxxx\.m2\repository\org\apache\velocity\velocity\1.7\velocity-1.7.jar;C:\Users\xxxxxx\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\xxxxxx\.m2\repository\commons-lang\commons-lang\2.4\commons-lang-2.4.jar;C:\Users\xxxxxx\.m2\repository\javax\servlet\jsp\jsp-api\2.2\jsp-api-2.2.jar;C:\Users\xxxxxx\.m2\repository\junit\junit\3.8.2\junit-3.8.2.jar;C:\Users\xxxxxx\.m2\repository\org\springframework\spring-context-support\4.3.9.RELEASE\spring-context-support-4.3.9.RELEASE.jar;C:\Users\xxxxxx\.m2\repository\com\xxxxxxx\xxxxxxx\440\xxxxxxx-440.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.331 s
[INFO] Finished at: 2017-06-28T15:13:05+01:00
[INFO] Final Memory: 13M/213M
[INFO] ------------------------------------------------------------------------
mvn验证

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xxx 2.0.1
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.109 s
[INFO] Finished at: 2017-06-28T15:15:32+01:00
[INFO] Final Memory: 7M/213M
[INFO] ------------------------------------------------------------------------
我真的被难住了。我假设maven使用的是与eclipse不同的编译器,但我真的没有什么想法了

以前有人遇到过这种情况吗


提前感谢。

我怀疑这是由于eclipse生成文件时出现编译错误(是的,eclipse可以做到:如果您从未获得不可编译的代码,那么您甚至不会出现错误)和Maven没有首先清理eclipse的输出

然后Maven看到文件是最新的,并且没有覆盖它

我建议如下(检查我是否正确):

  • 关闭Eclipse的自动构建(或完全停止Eclipse)
  • 运行Maven目标,例如
    package
    ,但也要运行
    clean
    (即
    mvn clean package
    );关键是要100%确保Maven构建这些文件,而不是Eclipse
  • Maven现在应该报告编译错误

至于错误本身,看起来您确实缺少了一个依赖项(但可能在Eclipse的类路径中,而不是在Maven的类路径中)。

因此,当将此项目与另一个成功的项目(都是从Java4转换而来)进行比较时,您会有一种预感,即使用非标准目录名是Maven不稳定行为的原因(在复制warSourceDirectory时)。我分析了(现在称为)WebRoot>WEB-INF>classes目录,并发现对于有问题的应用程序,这已经填充了,您已经猜到了-错误地编译了类文件!很明显,war插件将这些坏文件复制到了Maven拥有的文件之上,在相同的构建过程中刚刚成功地完成了-因此没有错误


我不确定为什么会有坏文件,因为它们不在旧的Java 4项目中。我怀疑它们一定是在以前失败的maven构建过程中使用不正确的设置创建的。

很长一段时间,但也许:您有“自动构建”吗已签入eclipse,但通过命令行运行?eclipse在与maven相同的时间在同一文件夹中进行自己的构建,可能会尝试这样做,并且可能会发生冲突。嗯,我通常在eclipse中进行maven构建“RunAs>maven clean”,然后“RunAs>maven install”。为了确保我尝试了自动关闭build,但仍然存在问题。:-/因此我尝试了自动关闭eclipses的build,然后在执行项目清理后(未选中start a build)完全关闭eclipse。然后在projects目录中运行mvn包(此时没有目标目录).mvn命令成功完成,没有错误,并创建了目标目录。然后我重新打开eclipse以查看生成的类文件的内容(因为我的文本编辑器不显示相同的视图)…唉,这是一样的。顺便说一句,在我的eclipse构建路径中,我只使用Maven依赖项,一旦在项目属性窗口中展开,就会出现javax.servlet-api-3.1.0.jar…我认为Maven一定是把这些未解决的编译问题留在那里,希望代码不会被获取?代码实际上是一个过滤器在web.xml中指定,因此在启动时会失败。有趣的是,我刚刚注意到,在目标目录中有一个类目录,其中包含(看起来是)正确编译的类。这是项目的.war文件和编译文件夹(其中包含错误编译的类)之外的内容.Eclipse类路径和Maven类路径可能略有不同。为什么这个jar显示为
提供的
?它不应该是
编译的
?javax.servlet:javax.servlet api:jar:3.1.0:提供感谢您的努力,Andrei。我找到了原因(回答如下)
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xxx 2.0.1
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.109 s
[INFO] Finished at: 2017-06-28T15:15:32+01:00
[INFO] Final Memory: 7M/213M
[INFO] ------------------------------------------------------------------------