gpt4 book ai didi

Java,Glassfish JPA : NoClassDefFoundError: javax/persistence/spi/PersistenceUnitInfo (JDK6/7 only)

转载 作者:太空狗 更新时间:2023-10-29 11:39:27 25 4
gpt4 key购买 nike

我对 Java EE6 和 Glassfish3 还很陌生。当我收到此错误时,我正在尝试构建自己的应用程序。

NoClassDefFoundError: javax/persistence/spi/PersistenceUnitInfo

假设这是一个无知问题,我开始学习本教程: http://netbeans.org/kb/docs/javaee/javaee-gettingstarted.html#Exercise_1

我仍然遇到同样的问题。确切的痕迹是:

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)

带有 PersistenceUnitInfo.classjavax.persistence.spi jar 确实存在于 Glassfish server 3 上,我可以通过 Netbeans 看到它。显式添加 JPA 库(EclipseLink、Persistence 等)的任何组合都无法阻止错误。
所以我完全被困在这一点上,为什么构建过程找不到合适的类。

有什么想法吗?

更新:我知道是什么原因造成的,但不确定为什么?在 Netbeans->Project properties->Libraries->Processor(tab) 中,它列出了 eclipselink (JPA2.0) 和 EclipseLink-ModelGen(JPA 2.0)。一旦我删除了那些它就起作用了。当您创建实体时,Netbeans 会自动添加它们。我正在运行 Netbeans 7.0.1。感谢大家的帮助。

最佳答案

根本原因只能是 JAR 不在运行时抛出异常的进程可用的类路径中。当您说 JAR“确实存在”时,您能否验证它在类路径中的存在?仅将其放在服务器安装下的文件夹中是不够的。

如果您在 Web 项目中有一个 WEB-INF 目录,您可以尝试将 JAR 复制到 WEB-INF/lib 目录,因为该目录中的 JAR 由 servlet 规范保证将作为类路径的一部分添加到类路径中应用程序安装。

关于Java,Glassfish JPA : NoClassDefFoundError: javax/persistence/spi/PersistenceUnitInfo (JDK6/7 only),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8306142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com