Eclipse警告:找不到类javax.persistence。* [英] Eclipse Warnings: class javax.persistence.* not found

查看:2130
本文介绍了Eclipse警告:找不到类javax.persistence。*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次真正使用Eclipse进行Java开发。我正在尝试使用EclipseLink的JPA实现。我将所有实体都移到了一个单独的包实体中。我在一个名为dataModeling的单独JPA项目中有 persistence.xml

This is my first time really playing around with Java development using Eclipse. I am trying to use EclipseLink's implementation of the JPA. I moved all of my entities into a separate package "entities". I have the persistence.xml in a separate JPA project called "dataModeling".

所有内容都可以构建并运行良好。

Everything builds and runs fine.

几乎每个项目都取决于我的实体。但是,我看到一个警告未找到类javax.persistence.Entity - 继续使用存根。等,因为依赖项目不引用EclipseLink。

Just about every project depends on my entities. However, I'm seeing a warning Class javax.persistence.Entity not found - continuing with a stub., etc. showing up because the dependent projects don't reference EclipseLink.

解决方案是进入每个依赖项目的属性,在 Java构建路径>库下,单击添加库,然后单击用户库,然后选择 EclipseLink

The solution is to go into each dependent project's properties and under Java Build Path > Libraries, click Add Library, then User Library and then select EclipseLink.

但是,对我来说,在每个项目中引用EclipseLink都没有意义!这是一个实现细节我不想给其他项目增加负担。看起来这种情况正在发生,因为其他项目看到了注释并且无法识别它们。

However, to me, it doesn't make sense to reference EclipseLink in every project! That's an implementation detail I don't want to burden other projects with. It looks like this is happening because the other projects see the annotations and don't recognize them.

所以真正的问题是:我如何使用JPA(通过注释)没有其他项目需要引用我的JPA实现?

So the real question is: how can I use JPA (via annotations) without every other project needing to reference my JPA implementation?

推荐答案

感谢@ neil-stockton和@chris,我能够弄清楚发生了什么。大多数JPA实现都有一个javax.persistence JAR的副本在某处浮动。他们中的大多数都与其他一切捆绑在一起,导致我的依赖性噩梦。似乎没有一个事实上的实现浮动。

Thanks to @neil-stockton and @chris, I was able to figure out what was going on. Most JPA implementations have a copy of the javax.persistence JAR floating around somewhere. Most of them are bundled with everything else, leading to my dependency nightmare. There doesn't appear to be a de facto implementation floating around.

在我的情况下,我使用了我的Eclipse插件目录下显示的副本。这些注释真的是空的,因为没有任何不需要的依赖。 JAR文件( javax.persistence ._< version> .jar )仅在我添加Dali和EclipseLink插件(一个或另一个)后才出现。

In my case, I used the copy that showed up under my Eclipse plugins directory. These annotations were truly empty in that did not have any unwanted dependencies. The JAR file (javax.persistence._<version>.jar) only showed up after I added the Dali and EclipseLink plugins (one or the other).

这篇关于Eclipse警告:找不到类javax.persistence。*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆