[Resolvido] [Java para WEB com JSF e JPA] Erro:java.lang.NoClassDefFoundError: javax/transaction/SystemException

Olá pessoal,

Estou iniciando no mundo Java agora, e comprei um livro citado acima para iniciar. comecei a seguir os passos do livro chegando na parte do cadastraAutomoveis.xhtml, incluir um automovel no banco. Quando tento executar o codigo no eclipse aparece a seguinte mensagem.

Poderiam me ajudar?

HTTP Status 500 - java.lang.NoClassDefFoundError: javax/transaction/SystemException

type Exception report

message java.lang.NoClassDefFoundError: javax/transaction/SystemException

description The server encountered an internal error that prevented it from fulfilling this request.

exception
javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/transaction/SystemException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause
javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: javax/transaction/SystemException
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause
java.lang.NoClassDefFoundError: javax/transaction/SystemException
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.jboss.logging.Logger$1.run(Logger.java:2554)
java.security.AccessController.doPrivileged(Native Method)
org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)
org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
org.hibernate.jpa.internal.HEMLogging.messageLogger(HEMLogging.java:28)
org.hibernate.jpa.internal.HEMLogging.messageLogger(HEMLogging.java:24)
org.hibernate.jpa.boot.internal.PersistenceXmlParser.(PersistenceXmlParser.java:55)
org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:80)
org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
persistence.JPAUtil.(JPAUtil.java:9)
bean.AutomovelBean.Salva(AutomovelBean.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:247)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause
java.lang.ClassNotFoundException: javax.transaction.SystemException
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.jboss.logging.Logger$1.run(Logger.java:2554)
java.security.AccessController.doPrivileged(Native Method)
org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)
org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
org.hibernate.jpa.internal.HEMLogging.messageLogger(HEMLogging.java:28)
org.hibernate.jpa.internal.HEMLogging.messageLogger(HEMLogging.java:24)
org.hibernate.jpa.boot.internal.PersistenceXmlParser.(PersistenceXmlParser.java:55)
org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:80)
org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
persistence.JPAUtil.(JPAUtil.java:9)
bean.AutomovelBean.Salva(AutomovelBean.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:247)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

note The full stack trace of the root cause is available in the Apache Tomcat/8.0.30 logs.

Apache Tomcat/8.0.30

Oi @tiago.tarinfo1, parece que só faltou adicionar a JTA no classpath.

Veja se o .jar dela está nas dependencias do Hibernate (não me lembro de cabeça se já vem junto). Se não tiver, você pode baixá-lo lá no repositório do maven: http://mvnrepository.com/artifact/javax.transaction/jta/1.1 e depois adicionar no classpath manualmente.

Isso deverá resolver o problema.

Olá Adriano…

 Muito obrigado pela ajuda... parece que resolveu uma parte..kkkkk

 mas desculpe o incomodo.kkkkk

 agora o erro mudou para:

HTTP Status 500 - java.lang.ExceptionInInitializerError

type Exception report

message java.lang.ExceptionInInitializerError

description The server encountered an internal error that prevented it from fulfilling this request.

exception
javax.servlet.ServletException: java.lang.ExceptionInInitializerError
javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause
javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause
java.lang.ExceptionInInitializerError
bean.AutomovelBean.Salva(AutomovelBean.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:247)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause
javax.persistence.PersistenceException: No Persistence provider for EntityManager named default
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
persistence.JPAUtil.(JPAUtil.java:9)
bean.AutomovelBean.Salva(AutomovelBean.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:247)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
javax.faces.component.UICommand.broadcast(UICommand.java:315)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

note The full stack trace of the root cause is available in the Apache Tomcat/8.0.30 logs.

Pessoal… funcionando…

para funcionar tirei a pasta META-INF (que continha o meu persistence.xml) da pasta WebContent(criada automaticamente quando gerei o projeto) e coloquei dentro da pasta SRC… dai funcionou.

Alguém poderia me explicar por que?

Boa @tiago.tarinfo1, parabéns.

O que acontece é que a pasta META-INF dentro do WebContent não faz parte do Classpath, então na hora que o aplicativo sobe pro servidor, a JPA procura o persistence.xml dentro do META-INF, mas não encontrava.

Já o que está no src faz parte do Classpath (na verdade, tudo que está dentro do src faz parte dele).

Muito Obrigado Adriano…

agora bora continuar os estudos…

ainda vou incomodar bastante.kkkkkk