TomEE 7.0.5 - 正确排除 JSF 2.2 jar 并包含 JSF 2.3 jar

TomEE 7.0.5 - properly exclude JSF 2.2 jar and include JSF 2.3 jar

如何防止 Tomee 提供 jsf 2.2 jar 并确保使用 jsf 2.3 jar?

这是 maven 配置问题还是缺少依赖问题或其他问题?

Tomcat 启动时的服务器日志包括警告:

WARNING: You are using the library: myfaces-impl in different versions; first (and probably used) version is: 2.2.12 loaded from: file:/path/to/Apache/TomEE/apache-tomee-plus-7.0.5/lib/myfaces-api-2.2.12.jar, but also found the following versions: 2.3.2 loaded from: file:/path/to/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/ProjectName/WEB-INF/lib/myfaces-api-2.3.2.jar

然后在服务器日志中找不到 TomcatAnnotationLifecycleProvider

的正确构造函数
    SEVERE: org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider
java.lang.InstantiationException: org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider
    at java.lang.Class.newInstance(Class.java:427)
    at org.apache.myfaces.shared.util.ClassUtils.newInstance(ClassUtils.java:426)
    at org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory.createClass(DefaultLifecycleProviderFactory.java:256)
    at org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory.resolveLifecycleProviderFromService(DefaultLifecycleProviderFactory.java:203)
    at org.apache.myfaces.config.annotation.DefaultLifecycleProviderFactory.getLifecycleProvider(DefaultLifecycleProviderFactory.java:86)
    at org.apache.myfaces.config.FacesConfigurator.configureManagedBeanDestroyer(FacesConfigurator.java:1522)
    at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:618)
    at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:465)
    at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:70)
    at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:189)
    at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:103)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4790)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5256)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodException: org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider.<init>()
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.newInstance(Class.java:412)
    ... 19 more

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">

<dependencies>  
<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-impl</artifactId>
    <version>2.3.2</version>
</dependency>
<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-api</artifactId>
    <version>2.3.2</version>
</dependency>
</dependencies>   

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</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>

我添加了一张脸-config.xml。这是完整的文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
    version="2.3">

    <!-- Config here. -->
</faces-config>

这是行不通的,因为 TomEE 集成仅针对 MyFaces 2.2 包和 SPI。在 2.3 开发期间,我们对 MyFaces 代码库进行了一些重构。我不认为你可以 运行 100%。

但是您可以只升级到 TomEE 8.0.0.M1,它已经集成了 MyFaces 2.3。