[英]Javax.persistance not available in TomEE
When running my Java EE app on TomEE I get the following error: 在TomEE上运行Java EE应用程序时,出现以下错误:
java.lang.NoClassDefFoundError: javax/persistence/NamedStoredProcedureQuery java.lang.NoClassDefFoundError:javax / persistence / NamedStoredProcedureQuery
There are no compile time errors when I build the app.I am developing in Eclipse and have Apache TomEE selected under targeted runtimes in the project properties, so that the project has access to Java EE. 生成应用程序时没有编译时错误。我正在Eclipse中进行开发,并在项目属性的目标运行 时下选择了Apache TomEE ,以便该项目可以访问Java EE。
As the project uses Hibernate I have the following jars in the WEB-INF\\lib directory (it's my understanding that these jars in turn use javax.persistence): 当项目使用Hibernate时,我在WEB-INF \\ lib目录中有以下jar(据我了解,这些jar依次使用javax.persistence):
I've seen a bunch of questions like this one detailing that the solution is to add the required JPA jar into the lib directory of the app and all will be well. 我已经看到了很多类似这样的问题,详细说明了解决方案是将所需的JPA jar添加到应用程序的lib目录中,一切都会很好。 But although that solution may work it sounds hacky to me, I want TomEE to manage the JPA libraries itself. 但是,尽管该解决方案可能行得通,但对我来说似乎有点棘手,但我希望TomEE自己管理JPA库。 It's a Java EE server so why doesn't it do this. 这是一台Java EE服务器,所以为什么不这样做。 Whats a clean solution? 什么是干净的解决方案?
@JB Nizet 's answer is the accepted solution: @JB Nizet的答案是公认的解决方案:
This class exists since JPA 2.1. 从JPA 2.1开始存在此类。 I guess your TomEE version only supports JPA 2.0. 我猜您的TomEE版本仅支持JPA 2.0。 And indeed, thehome page of TomEE says: "Java EE 6 Web Profile". 实际上,TomEE的主页上显示:“ Java EE 6 Web Profile”。 Java EE 6 includes JPA 2.0, not 2.1. Java EE 6包含JPA 2.0,而不是2.1。 – JB Nizet – JB Nizet
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.