title: Cannot deploy WAR: ClassNotFoundException - What am I still missing?
body: <p>I'm building a project based on Spring and Hibernate inspired to a <a href="http://briansjavablog.blogspot.it/2012/08/rest-services-with-spring.html" rel="nofollow noreferrer">Spring MVC tutorial</a> I downloaded. I basically inherited <code>pom.xml</code> and constructed the Eclipse project by it, writing Java code from scratch. Anyway, I'm sure mine is a dependency problem.</p>
  
  <p>Yesterday I added Java EE dependency to <code>pom.xml</code> because of a <code>NoClassDefFoundError: javax/persistence/Entity</code> when loading Hibernate. I Googled and got suggested to add Java EE</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;javax&lt;/groupId&gt;
      &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
      &lt;version&gt;6.0&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>However now I'm getting <code>SEVERE: Error configuring application listener of class com.sun.faces.config.ConfigureListener
  java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener</code></p>
  
  <p>My project is a Spring MVC REST API. I have read that this error is caused by missing JSF implementation but I don't need JSF here nor I know how to add it to pom.xml if I really need it.</p>
  
  <p>I found no reference to this class in <code>web.xml</code> (so I could work without it). It doesn't seem required by Hibernate AFAIK (HB works on plain old Java console apps too, no need for JSF).</p>
  
  <h2>How can I fix the project?</h2>
  
  <p>Additional info:</p>
  
  <p>Full web.xml dump</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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/web-app_2_5.xsd"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      id="WebApp_ID" version="2.5"&gt;
      &lt;display-name&gt;J Trust Wrapper&lt;/display-name&gt;
      &lt;!-- Main configuration file for this Spring web application. --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;  
                   /WEB-INF/config/rest-services-config.xml  
              &lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;!-- Loads the Spring web application context using the config file defined 
          above. --&gt;
      &lt;!-- &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt; 
          &lt;/listener&gt; --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;!-- Define the Spring Dispatcher Servlet for the REST services. The 'contextConfiguration' 
          param with an empty value means that the Spring Context won't try to load 
          a default file called restservices-servlet.xml --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;restservices&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;!-- This Servlet mapping means that this Servlet will handle all incoming 
          requests --&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;restservices&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>project layout
  <img src="https://i.stack.imgur.com/93ci2.png" alt="Project layout"></p>
  
  <p>Before adding Java EE reference <strong>or</strong> when following <a href="https://stackoverflow.com/questions/5967905/error-with-jboss-while-deploying-a-jsp-servlet-web-app-com-sun-faces-config-con">this advice</a></p>
  
  <pre><code>SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/config/rest-services-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/persistence/Entity
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/config/rest-services-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/persistence/Entity
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:767)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:698)
      at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:519)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:319)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:298)
      at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1150)
      at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:105)
      at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initApplicationContext(AbstractHandlerMethodMapping.java:89)
      at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
      at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
      at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
      at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
      at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      ... 21 more
  Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/persistence/Entity
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
      ... 38 more
  Caused by: java.lang.NoClassDefFoundError: javax/persistence/Entity
      at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean.&lt;init&gt;(AnnotationSessionFactoryBean.java:90)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
      ... 40 more
  Caused by: java.lang.ClassNotFoundException: javax.persistence.Entity
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      ... 46 more
  </code></pre>
  
  <p>After adding Java EE reference (without scope as suggested in the answer linked above)</p>
  
  <pre><code>SEVERE: Error configuring application listener of class com.sun.faces.config.ConfigureListener
  java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
      at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
      at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4733)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>JRE in use is <code>/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0</code></p>