Getting error: "wrong fragment name at web.xml absolute-ordering tag"
Getting error: "wrong fragment name at web.xml absolute-ordering tag"
我正在将应用程序转换为 Maven,并更新到 Tomcat 9、OpenJDK-11、JSF 2.3 和 PrimeFaces 7.0。前两部分成功进行,但我在更新 JSF 时遇到了困难。一个障碍是通过在 OpenJDK 11 中导入 CDI 支持来调整 JSF 删除托管 bean。我认为我已经包含了所有正确的库并进行了适当的注释更改。现在的问题是我收到以下错误:
WARNING: Used a wrong fragment name [acme_common] at web.xml absolute-ordering tag!
然后是 ApplicationContextListener 的 ClassNotFound 异常。
设置是我有主应用程序项目,我们称它为acme-main
,以及一个包含所有第三方库、框架等的公共项目acme-common
。主要项目 acme-main
有一个 web.xml 像这样:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<absolute-ordering>
<name>acme_common</name>
</absolute-ordering>
<listener>
<listener-class>com.acme.application.app.MainApplicationContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
common项目然后在web-fragment.xml:
中拥有所有框架过滤器、servlets等
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
metadata-complete="true" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
<name>acme_common</name>
<!-- Various App Filters -->
<!-- Various App Servlets -->
<!-- Various App Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Various Context Parameters -->
</web-fragment>
这里是控制台输出,略有修整:
Dec 02, 2019 10:03:50 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:acme-main' did not find a matching property.
...
Dec 02, 2019 10:03:50 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: ...
Dec 02, 2019 10:03:50 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Dec 02, 2019 10:03:51 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Dec 02, 2019 10:03:51 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Dec 02, 2019 10:03:51 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Dec 02, 2019 10:03:51 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1119 ms
Dec 02, 2019 10:03:51 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Dec 02, 2019 10:03:51 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/9.0.8
...
Dec 02, 2019 10:03:52 AM org.apache.tomcat.util.descriptor.web.WebXml orderWebFragments
WARNING: Used a wrong fragment name [acme_common] at web.xml absolute-ordering tag!
Dec 02, 2019 10:03:52 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Dec 02, 2019 10:03:52 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class [com.acme.application.app.MainApplicationContextListener]
java.lang.ClassNotFoundException: com.acme.application.app.MainApplicationContextListener
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1292)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1121)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4549)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5091)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Dec 02, 2019 10:03:52 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
"wrong fragment name" 和 ClassNotFound 错误听起来都像 buildpath/classpath 问题,但 acme-main 在构建路径中肯定有 acme-common 作为项目参考(我在 Eclipse 中开发) .奇怪的是,ClassNotFound class (MainAppContextListener) 是在 acme-main 项目中定义的。
谷歌搜索 "wrong fragment" 错误没有发现任何问题。正如我所说,这个项目配置一直在工作,并且将当前配置与过去进行比较,我也没有看到任何可疑之处。我没有想法,如果有任何建议,我将不胜感激。
我终于解决了这个问题。我推断要找到 web 片段,acme-common.jar 应该出现在 Eclipse 的服务器文件位置,在 META-INF/lib 下。当我发现它丢失时,我专注于 Eclipse 的构建程序集。我认为问题的发生是因为在 Java 构建路径、顺序和导出选项卡上,我有未导出的部分,and/or acme-common.jar 未包含在Web 部署程序集。我怀疑我在项目的 maven 和非 maven 版本之间切换导致了其中一些项目设置。
所以虽然这最终是一个非常狭窄的问题,但我会留下这个问题以防它对任何人有用。
我正在将应用程序转换为 Maven,并更新到 Tomcat 9、OpenJDK-11、JSF 2.3 和 PrimeFaces 7.0。前两部分成功进行,但我在更新 JSF 时遇到了困难。一个障碍是通过在 OpenJDK 11 中导入 CDI 支持来调整 JSF 删除托管 bean。我认为我已经包含了所有正确的库并进行了适当的注释更改。现在的问题是我收到以下错误:
WARNING: Used a wrong fragment name [acme_common] at web.xml absolute-ordering tag!
然后是 ApplicationContextListener 的 ClassNotFound 异常。
设置是我有主应用程序项目,我们称它为acme-main
,以及一个包含所有第三方库、框架等的公共项目acme-common
。主要项目 acme-main
有一个 web.xml 像这样:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<absolute-ordering>
<name>acme_common</name>
</absolute-ordering>
<listener>
<listener-class>com.acme.application.app.MainApplicationContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
common项目然后在web-fragment.xml:
中拥有所有框架过滤器、servlets等<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
metadata-complete="true" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
<name>acme_common</name>
<!-- Various App Filters -->
<!-- Various App Servlets -->
<!-- Various App Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Various Context Parameters -->
</web-fragment>
这里是控制台输出,略有修整:
Dec 02, 2019 10:03:50 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:acme-main' did not find a matching property.
...
Dec 02, 2019 10:03:50 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: ...
Dec 02, 2019 10:03:50 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Dec 02, 2019 10:03:51 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Dec 02, 2019 10:03:51 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Dec 02, 2019 10:03:51 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Dec 02, 2019 10:03:51 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1119 ms
Dec 02, 2019 10:03:51 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Dec 02, 2019 10:03:51 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/9.0.8
...
Dec 02, 2019 10:03:52 AM org.apache.tomcat.util.descriptor.web.WebXml orderWebFragments
WARNING: Used a wrong fragment name [acme_common] at web.xml absolute-ordering tag!
Dec 02, 2019 10:03:52 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Dec 02, 2019 10:03:52 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class [com.acme.application.app.MainApplicationContextListener]
java.lang.ClassNotFoundException: com.acme.application.app.MainApplicationContextListener
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1292)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1121)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4549)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5091)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Dec 02, 2019 10:03:52 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
"wrong fragment name" 和 ClassNotFound 错误听起来都像 buildpath/classpath 问题,但 acme-main 在构建路径中肯定有 acme-common 作为项目参考(我在 Eclipse 中开发) .奇怪的是,ClassNotFound class (MainAppContextListener) 是在 acme-main 项目中定义的。
谷歌搜索 "wrong fragment" 错误没有发现任何问题。正如我所说,这个项目配置一直在工作,并且将当前配置与过去进行比较,我也没有看到任何可疑之处。我没有想法,如果有任何建议,我将不胜感激。
我终于解决了这个问题。我推断要找到 web 片段,acme-common.jar 应该出现在 Eclipse 的服务器文件位置,在 META-INF/lib 下。当我发现它丢失时,我专注于 Eclipse 的构建程序集。我认为问题的发生是因为在 Java 构建路径、顺序和导出选项卡上,我有未导出的部分,and/or acme-common.jar 未包含在Web 部署程序集。我怀疑我在项目的 maven 和非 maven 版本之间切换导致了其中一些项目设置。
所以虽然这最终是一个非常狭窄的问题,但我会留下这个问题以防它对任何人有用。