开发者

Maven tomcat:run goal and jsf annotation based component/converter/validator scanning

I'm developing a JSF 2.0 application (Mojarra+Primefaces) and using the maven build environment. Before I have used the faces-config.xml file for registering of my custom converters and validators, everything went well so far. Then I saw some syntactic sugar of JSF 2.0 - the annotation based configuration approach. And now I would like to use it, instead of the xml config file. A problem was that Mojarra didn't 开发者_C百科scan my annotated classes. I figured out that I needed to put the <faces-config ... metadata-complete="false"> attribute to false. Now it works but only if I start my application with mvn tomcat:run-war goal and not with the mvn tomcat:run dynamic project, which is more comfortable for development. The specification of JSP 2.0 says that:

If the element in the WEB-INF/faces-config.xml file contains metadata-complete attribute whose value is "true", the implementation must not perform annotation scanning on any classes except for those classes provided by the implementation itself. Otherwise, continue as follows.

If the runtime discovers a conflict between an entry in the Application Configuration Resources and an annotation, the entry in the Application Configuration Resources takes precedence. All classes in WEB-INF/classes must be scanned.

For every jar in the application's WEB-INF/lib directory, if the jar contains a "META-INF/faces-config.xml" file or a file that matches the regular expression ".*.faces-config.xml" (even an empty one), all classes in that jar must be scanned.

But it says nothing about dynamic projects running in maven build environment :)! Do anyone has a solution for that problem?

Cheers,

Kevin


I also had this problem, but found that adding the war:inplace goal made it work for me. i.e. use

mvn clean war:inplace tomcat:run

instead of just 'tomcat:run' and it should work just fine.


In my case the Log4jServletContainerInitializer in log4j-web was somehow preventing the FacesInitializer in javax.faces from being called, which is responsible for processing annotated JSF classes.

Using tomcat8-maven-plugin and embedded tomcat 8.0.52.

war:inplace worked, or just removing log4j-web (with manual log4j initialization and context management).


Adding org.apache.myfaces.annotation.SCAN_PACKAGES fixed the tomcat7:run goal for me

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜