OpenWebBeans gives error java.lang.NoClassDefFoundError when using with Tomcat 10

1.3k views Asked by At

I am trying to use OpenWebBeans with Tomcat 10. I have followed the steps given in this link.

When I use Weld, it works fine. But when I use OpenWebBeans, I get the following error.

SEVERE: Error configuring application listener of class [org.apache.webbeans.servlet.WebBeansConfigurationListener]
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener ... 

My pom file is as follows

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>minimal</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
    <project.build.sourceEncoding>
        UTF-8
    </project.build.sourceEncoding>
    <project.reporting.outputEncoding>
        UTF-8
    </project.reporting.outputEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
    <dependency>
        <groupId>jakarta.annotation</groupId>
        <artifactId>jakarta.annotation-api</artifactId>
        <version>2.0.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>jakarta.faces</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>jakarta.servlet.jsp.jstl</groupId>
        <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>jakarta.enterprise</groupId>
        <artifactId>jakarta.enterprise.cdi-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.openwebbeans</groupId>
        <artifactId>openwebbeans-jsf</artifactId>
        <version>2.0.21</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>7.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>jakarta.servlet</groupId>
        <artifactId>jakarta.servlet-api</artifactId>
        <version>5.0.0</version>
    </dependency>
</dependencies>
</project>

This is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>minimal</display-name>
<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.apache.webbeans.servlet.WebBeansConfigurationListener
</listener-class>
</listener>

This is my context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XML>
<Context>
<Resource name="BeanManager" 
    auth="Container"
    type="jakarta.enterprise.inject.spi.BeanManager"
    factory="org.apache.webbeans.container.ManagerObjectFactory" />
</Context>

I am required to migrate to the jakarta namespace using OpenWebBeans. Any help would be highly appreciated.

1

There are 1 answers

1
BalusC On BEST ANSWER

I am required to migrate to the jakarta namespace using OpenWebBeans.

They do have a Jakartified version since 2.0.15. Simply add <classifier>jakarta</classifier> to the dependency.

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-jsf</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
</dependency>

It has currently however only one problem: its four transitive dependencies web, el22, impl and spi are incorrectly not the Jakartified variants. So you need to explicitly exclude them and explicitly include the Jakartified variants. So you're forced to end up with this monster graph:

<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-jsf</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
    <exclusions>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-web</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-el22</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-impl</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-spi</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-web</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
    <exclusions>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-el22</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-impl</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-spi</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-el22</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
</dependency>
<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-impl</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
    <exclusions>
        <exclusion>
            <groupId>org.apache.openwebbeans</groupId>
            <artifactId>openwebbeans-spi</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.openwebbeans</groupId>
    <artifactId>openwebbeans-spi</artifactId>
    <version>2.0.21</version>
    <classifier>jakarta</classifier>
</dependency>