Maven编译静默失败-未解决的编译问题 [英] Maven compile fails silently - Unresolved compilation problems

查看:47
本文介绍了Maven编译静默失败-未解决的编译问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Spring WebApp Maven构建时遇到了一个有趣的问题.当在eclipse内构建时,一切都很好,但是通过maven构建并部署到tomcat 8容器中时,webapp启动失败,并显示以下错误:

I have an interesting problem with a spring webapp maven build. When being built inside eclipse everything is fine yet when built via maven and deployed to a tomcat 8 container the webapp fails on startup with the following error:

Caused by: java.lang.NoClassDefFoundError: FilterConfig

现在,我尝试了所有明显且有据可查的依赖性问题(设置javax.servlet-api& jsp-api导入中提供的范围,并确保它们是最新版本,因为这是Java 8项目).我确保所有的Complier插件都是最新版本:

Now I tried all the obvious and well documented dependency issues (setting scope provided on the javax.servlet-api & jsp-api import and making sure they are of the latest versions as this is a Java 8 project). I have made sure all of the complier plugins are of the latest versions:

maven-war-plugin3.1.0

maven-war-plugin 3.1.0

maven-compiler-plugin3.6.1

maven-compiler-plugin 3.6.1

然而,Web应用程序无法启动,并且在Maven构建控制台输出中未显示任何错误.在(工作)日食构建与神秘失败的Maven等价物进行了艰苦的努力之后,我们发现在Maven生成的某些类文件中是描述编译问题的文本.(以下内容摘自Eclipse中针对.class文件的打开方式>文本编辑器"选项-由于某些字符无法正确复制,因此必须将其省略)

yet the webapp fails to start with no errors being shown in the maven build console output. After much head-scratching and painstaking comparison between the (working) eclipse build and the mysteriously failing maven equivalent it was discovered that inside some of the class files generated by maven were texts describing compilation problems. (The following was extracted from the "Open With > Text Editor" option in eclipse against the .class file - some of the characters had to be omitted as they wouldn't copy correctly)

Unresolved compilation problems: 
    The import javax.servlet.Filter cannot be resolved
    The import javax.servlet.FilterChain cannot be resolved
    The import javax.servlet.FilterConfig cannot be resolved
    The import javax.servlet.ServletException cannot be resolved
    The import javax.servlet.ServletRequest cannot be resolved
    The import javax.servlet.ServletResponse cannot be resolved
    The import javax.servlet.http.HttpServletRequest cannot be resolved
    The import javax.servlet.http.HttpSession cannot be resolved
    Filter cannot be resolved to a type
    FilterConfig cannot be resolved to a type
    ServletException cannot be resolved to a type
    ServletRequest cannot be resolved to a type
    ServletResponse cannot be resolved to a type
    FilterChain cannot be resolved to a type
    ServletException cannot be resolved to a type
    HttpServletRequest cannot be resolved to a type
    HttpServletRequest cannot be resolved to a type
    HttpSession cannot be resolved to a type

我无法理解Maven流程如何成功完成,并且我尝试过的任何mvn目标都未显示任何错误

I cannot understand how the maven process appears to complete successfully and that no errors are shown with any of the mvn goals I've tried

mvn complier:compile

mvn complier:compile

[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的命令显示了很多调试输出,但是没有任何提示编译问题的信息,实际上,它指出包含了类文件标识的未解决的依赖项

the above but with the -x showed a lot of debugging output but nothing to suggest compile problems, in fact it states that the class-file identified unresolved dependencies are included

...
[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依赖项:build-classpath

mvn dependency:build-classpath

[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不同的编译器,但我的想法真的耗尽了.

I really am stumped. I'm presuming maven is using a different compiler from eclipse but I really have run out of ideas.

之前有人遇到过吗?

谢谢.

推荐答案

因此,在将该项目与另一个成功的项目(都是从Java 4转换而来)进行比较时,直觉会使用非标准目录名称是造成Maven的原因行为不稳定(在复制warSourceDirectory时).我分析了(现在称为)WebRoot> WEB-INF> classes目录,发现对于有问题的应用程序,您已经猜到它已被填充-错误地编译了类文件!显然,war插件将这些错误的文件复制到了Maven的文件之上,并且在同一编译过程中就成功地完成了编译-因此没有错误.

So when comparing this project to another successful project (that were both converted from Java 4), on the hunch that using non standard directory names was the cause for mavens erratic behavior (while copying the warSourceDirectory). I analysed the (now called) WebRoot > WEB-INF > classes directory and discovered that for the problematic app this had been populated, with you've guessed it - incorrectly compiled class files! Clearly the war plugin copied these bad files over the top of the files Maven had, in the same build process just successfully complied - hence no error.

我不确定为什么坏文件在那里,因为它们不在旧的Java 4项目中.我怀疑它们一定是在以前的Maven构建失败时使用不正确的设置以某种方式创建的.

I am unsure why the bad files were there as they were not in the old Java 4 project. I suspect that they must have been created somehow during a previous failed maven build using incorrect settings.

这篇关于Maven编译静默失败-未解决的编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆