title: Java, Glassfish JPA: NoClassDefFoundError: javax/persistence/spi/PersistenceUnitInfo (JDK6/7 only)
body: <p>I'm fairly new to Java EE6 and Glassfish3. I was trying to build my own application when I got this error. </p>
  
  <blockquote>
    <p>NoClassDefFoundError: javax/persistence/spi/PersistenceUnitInfo</p>
  </blockquote>
  
  <p>Assuming it was an ignorance issue I started following this tutorial: 
  <a href="http://netbeans.org/kb/docs/javaee/javaee-gettingstarted.html#Exercise_1" rel="nofollow">http://netbeans.org/kb/docs/javaee/javaee-gettingstarted.html#Exercise_1</a></p>
  
  <p>I still got the same issue. The exact trace is: </p>
  
  <blockquote>
    <p>An annotation processor threw an uncaught exception. Consult the
    following stack trace for details. java.lang.NoClassDefFoundError:
    javax/persistence/spi/PersistenceUnitInfo     at
    org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:350)
      at
    com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
      at
    com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
      at
    com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
      at
    com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
      at
    com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
      at
    com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1106)
      at
    com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
      at com.sun.tools.javac.main.Main.compile(Main.java:417)     at
    com.sun.tools.javac.main.Main.compile(Main.java:331)  at
    com.sun.tools.javac.main.Main.compile(Main.java:322)  at
    com.sun.tools.javac.Main.compile(Main.java:76)    at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)     at
    org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
      at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1134)     at
    org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:912)   at
    org.netbeans.modules.java.source.ant.JavacTask.execute(JavacTask.java:144)
      at
    org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
      at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)     at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)     at
    org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
      at org.apache.tools.ant.Task.perform(Task.java:348)     at
    org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
      at
    org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
      at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)     at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)     at
    org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
      at org.apache.tools.ant.Task.perform(Task.java:348)     at
    org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
      at
    org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
      at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)     at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)     at
    org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
      at org.apache.tools.ant.Task.perform(Task.java:348)     at
    org.apache.tools.ant.Target.execute(Target.java:390)  at
    org.apache.tools.ant.Target.performTasks(Target.java:411)     at
    org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1368)    at
    org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1251)   at
    org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
      at
    org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
      at
    org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
    Caused by: java.lang.ClassNotFoundException:
    javax.persistence.spi.PersistenceUnitInfo     at
    java.net.URLClassLoader$1.run(URLClassLoader.java:366)    at
    java.net.URLClassLoader$1.run(URLClassLoader.java:355)    at
    java.security.AccessController.doPrivileged(Native Method)    at
    java.net.URLClassLoader.findClass(URLClassLoader.java:354)    at
    java.lang.ClassLoader.loadClass(ClassLoader.java:423)     at
    java.lang.ClassLoader.loadClass(ClassLoader.java:356)     ... 49 more
    /home/alan/Projects/SimpleEE6App/SimpleEE6App/nbproject/build-impl.xml:550:
    The following error occurred while executing this line:
    /home/alan/Projects/SimpleEE6App/SimpleEE6App/nbproject/build-impl.xml:263:
    Compile failed; see the compiler error output for details. BUILD
    FAILED (total time: 0 seconds)</p>
  </blockquote>
  
  <p>The <code>javax.persistence.spi</code> jar with the <code>PersistenceUnitInfo.class</code> does exist on the Glassfish server 3, I can see it through Netbeans. Explicitly adding any combination of JPA libraries (EclipseLink, Persistence, etc.) does nothing to stop the error.<br>
  So I'm totally stuck at this point as to why the build process cannot find the appropriate class.</p>
  
  <p>Any ideas?</p>
  
  <p>Update: I figured out what was causing it but am not sure why? In Netbeans->Project properties->Libraries->Processor(tab) it listed eclipselink (JPA2.0) and EclipseLink-ModelGen(JPA 2.0). Once I removed those it worked. Netbeans adds them automatically when you create an entity. I'm running Netbeans 7.0.1. 
  Thanks for everybody's help.</p>