Issue
I'm converting an application to Maven, as well as updating to Tomcat 9, OpenJDK-11, JSF 2.3, and PrimeFaces 7.0. The first two parts went successfully, but I've hit a wall with updating JSF. One hurdle was adjusting for JSF dropping managed beans by importing CDI support in OpenJDK 11. I think I've included all the right libraries and made the appropriate annotation changes. The problem now is that I get the following error:
WARNING: Used a wrong fragment name [acme_common] at web.xml absolute-ordering tag!
and afterwards, a ClassNotFound exception for the ApplicationContextListener.
The set-up is that I have the main application project, let's call it acme-main
, and a common project acme-common
containing all the third-party libraries, frameworks, etc. The main project acme-main
has a web.xml like so:
<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>
The common project then has all the framework filters, servlets, etc. in a web-fragment.xml:
<?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>
Here's the console output, slightly trimmed:
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)
The "wrong fragment name" and ClassNotFound errors both sound like buildpath/classpath problems, but acme-main definitely has acme-common in the build path and as a project reference (I'm developing in Eclipse). And oddly, the ClassNotFound class (MainAppContextListener) is defined in the acme-main project.
Googling for the "wrong fragment" error has revealed nothing. As I said, this project configuration had been working, and I don't see anything suspicious in comparing the current configuration with the past either. I'm out of ideas and would appreciate any suggestions.
Solution
I finally resolved this issue. I'd reasoned that for the web-fragment to be found, the acme-common.jar should be present in the Eclipse's Server files location, under META-INF/lib. When I found it missing I focused on Eclipse's build assembly. I believe the problem occurred because on the Java Build Path, Order and Export tab, I had parts that weren't being exported, and/or that acme-common.jar wasn't included in the Web Deployment Assembly. I suspect my switching between maven and non-maven versions of the project threw off some of these project settings.
So while this was ultimately a very narrow issue, I'll leave the question posted in case it's ever of use to anyone.
Answered By - Didjit