NoClassDefFoundError: javax/inject/Provider and ClassNotFoundException: javax.inject.Provider

masterdany88 picture masterdany88 · Nov 26, 2016 · Viewed 16.3k times · Source

I am getting those errors:

lis 26, 2016 8:51:16 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:erpe-server' did not find a matching property.
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.36
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Jun 9 2016 13:55:50 UTC
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.36.0
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Linux
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            4.4.0-34-generic
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /usr/lib/jvm/java-8-oracle/jre
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_101-b13
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /home/korbeldaniel/Documents/workspace-sts-3.8.1.RELEASE/.metadata/.plugins/org.eclipse.wst.server.core/tmp1
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /home/korbeldaniel/Documents/apache-tomcat-8.0.36
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:34576
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/home/korbeldaniel/Documents/workspace-sts-3.8.1.RELEASE/.metadata/.plugins/org.eclipse.wst.server.core/tmp1
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/home/korbeldaniel/Documents/apache-tomcat-8.0.36
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/home/korbeldaniel/Documents/workspace-sts-3.8.1.RELEASE/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/home/korbeldaniel/Documents/apache-tomcat-8.0.36/endorsed
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
lis 26, 2016 8:51:16 PM 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: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
lis 26, 2016 8:51:16 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
lis 26, 2016 8:51:16 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
lis 26, 2016 8:51:16 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
lis 26, 2016 8:51:16 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
lis 26, 2016 8:51:16 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 680 ms
lis 26, 2016 8:51:16 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
lis 26, 2016 8:51:16 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.36
lis 26, 2016 8:51:19 PM 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.
lis 26, 2016 8:51:19 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
lis 26, 2016 8:51:20 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: javax/inject/Provider
    at com.google.inject.internal.MoreTypes.canonicalizeForKey(MoreTypes.java:81)
    at com.google.inject.Key.<init>(Key.java:119)
    at com.google.inject.Key.get(Key.java:212)
    at com.google.inject.spi.Elements$RecordingBinder.bind(Elements.java:262)
    at com.google.inject.internal.InjectorShell$RootModule.configure(InjectorShell.java:276)
    at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
    at com.google.inject.spi.Elements.getElements(Elements.java:101)
    at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
    at com.google.inject.Guice.createInjector(Guice.java:95)
    at com.google.inject.Guice.createInjector(Guice.java:72)
    at com.google.inject.Guice.createInjector(Guice.java:62)
    at org.jboss.errai.bus.server.service.ErraiServiceFactory.create(ErraiServiceFactory.java:30)
    at org.jboss.errai.bus.server.service.ErraiServiceSingleton.initSingleton(ErraiServiceSingleton.java:39)
    at org.jboss.errai.bus.server.servlet.ServletBootstrapUtil.initService(ServletBootstrapUtil.java:111)
    at org.jboss.errai.bus.server.servlet.ServletBootstrapUtil.getService(ServletBootstrapUtil.java:61)
    at org.jboss.errai.bus.server.servlet.AbstractErraiServlet.init(AbstractErraiServlet.java:86)
    at org.jboss.errai.bus.server.servlet.DefaultBlockingServlet.init(DefaultBlockingServlet.java:91)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5337)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: javax.inject.Provider
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
    ... 30 more

lis 26, 2016 8:51:20 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [ErraiServlet] in web application [/erpe-server] threw load() exception
java.lang.ClassNotFoundException: javax.inject.Provider
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
    at com.google.inject.internal.MoreTypes.canonicalizeForKey(MoreTypes.java:81)
    at com.google.inject.Key.<init>(Key.java:119)
    at com.google.inject.Key.get(Key.java:212)
    at com.google.inject.spi.Elements$RecordingBinder.bind(Elements.java:262)
    at com.google.inject.internal.InjectorShell$RootModule.configure(InjectorShell.java:276)
    at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
    at com.google.inject.spi.Elements.getElements(Elements.java:101)
    at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
    at com.google.inject.Guice.createInjector(Guice.java:95)
    at com.google.inject.Guice.createInjector(Guice.java:72)
    at com.google.inject.Guice.createInjector(Guice.java:62)
    at org.jboss.errai.bus.server.service.ErraiServiceFactory.create(ErraiServiceFactory.java:30)
    at org.jboss.errai.bus.server.service.ErraiServiceSingleton.initSingleton(ErraiServiceSingleton.java:39)
    at org.jboss.errai.bus.server.servlet.ServletBootstrapUtil.initService(ServletBootstrapUtil.java:111)
    at org.jboss.errai.bus.server.servlet.ServletBootstrapUtil.getService(ServletBootstrapUtil.java:61)
    at org.jboss.errai.bus.server.servlet.AbstractErraiServlet.init(AbstractErraiServlet.java:86)
    at org.jboss.errai.bus.server.servlet.DefaultBlockingServlet.init(DefaultBlockingServlet.java:91)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5337)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

lis 26, 2016 8:51:20 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
lis 26, 2016 8:51:20 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
lis 26, 2016 8:51:20 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3374 ms

I can not figure this out. I have multimodule maven project, and this issue is releated to the server code that runs on tomcat container.

Please help.

This is my pom:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>pl.korbeldaniel.erpe</groupId>
        <artifactId>erpe</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>erpe-server</artifactId>
    <packaging>war</packaging>

    <prerequisites>
        <maven>${mavenVersion}</maven>
    </prerequisites>

    <properties>
        <errai.version>4.0.0.Beta4</errai.version>
        <spring.version>4.2.1.RELEASE</spring.version>
        <spring-security.version>4.0.3.RELEASE</spring-security.version>
        <spring-data.version>1.9.1.RELEASE</spring-data.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>erpe-shared</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-servlet</artifactId>
        </dependency>
        <!-- Spring starts -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${spring-data.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <!-- Spring ends -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.jboss.errai/errai-bus -->
        <dependency>
            <groupId>org.jboss.errai</groupId>
            <artifactId>errai-bus</artifactId>
            <version>${errai.version}</version>
        </dependency>

    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <configuration>
                        <skip>false</skip>
                        <scanIntervalSeconds>1</scanIntervalSeconds>
                        <webApp>
                            <extraClasspath>${basedir}/../erpe-shared/target/classes/</extraClasspath>
                        </webApp>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat6-maven-plugin</artifactId>
                    <configuration>
                        <addWarDependenciesInClassloader>false</addWarDependenciesInClassloader>
                        <path>/</path>
                        <uriEncoding>UTF-8</uriEncoding>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <configuration>
                        <addWarDependenciesInClassloader>false</addWarDependenciesInClassloader>
                        <path>/</path>
                        <uriEncoding>UTF-8</uriEncoding>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <!-- XXX: We want to exclude erpe-client from 'env-dev' profile, Maven 
                forces us to make a 'env-prod' profile -->
            <id>env-prod</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>erpe-client</artifactId>
                    <version>${project.version}</version>
                    <type>war</type>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>env-dev</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>dev</value>
                </property>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.eclipse.jetty</groupId>
                            <artifactId>jetty-maven-plugin</artifactId>
                            <configuration>
                                <webApp>
                                    <baseResource
                                        implementation="org.eclipse.jetty.util.resource.ResourceCollection">
                                        <resourcesAsCSV>src/main/webapp,${basedir}/../target/gwt/launcherDir/</resourcesAsCSV>
                                    </baseResource>
                                </webApp>
                                <systemProperties>
                                    <systemProperty>
                                        <name>gwt.codeserver.port</name>
                                        <value>9876</value>
                                    </systemProperty>
                                </systemProperties>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.tomcat.maven</groupId>
                            <artifactId>tomcat6-maven-plugin</artifactId>
                            <configuration>
                                <contextFile>${basedir}/src/main/tomcatconf/context.xml</contextFile>
                                <systemProperties>
                                    <gwt.codeserver.port>9876</gwt.codeserver.port>
                                </systemProperties>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.tomcat.maven</groupId>
                            <artifactId>tomcat7-maven-plugin</artifactId>
                            <configuration>
                                <contextFile>${basedir}/src/main/tomcatconf/context.xml</contextFile>
                                <systemProperties>
                                    <gwt.codeserver.port>9876</gwt.codeserver.port>
                                </systemProperties>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>
</project>

Answer

masterdany88 picture masterdany88 · Dec 3, 2016

Adding those dependenies fixed the problem:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>${javax.servlet.version}</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>3.0</version>
</dependency>
<dependency>
    <groupId>javax.inject</groupId>
    <artifactId>javax.inject</artifactId>
    <version>${javax.inject.version}</version>
</dependency>