从 POJO 读取 persistence.xml
我创建了一个 EJB3 项目和一个 JPA 项目。我正在尝试创建一个帮助程序类(它将位于一个单独的项目/jar 中),它将从位于我的 JPA 项目的 META-INF 文件夹中的 persistance.xml 文件返回持久性单元名称。
如何将此文件作为输入流读取?一旦获得对此文件的引用,我就可以解析这些值,但是如何从另一个 jar 的类中读取 jar 的 META-INF 文件夹中的文件?
请提供您的建议。
I have created an EJB3 project and a JPA project. I'm trying to create a helper class(which will be in a separate project/jar) that will return the Persistence Unit Name from the persistance.xml file which is in the META-INF folder of my JPA project.
How can I read this file as an Input Stream? I can parse the values once I get a reference to this file, but how do I read the files in META-INF folder of a jar from a class of another jar?
Please provide your suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在使用持久性单元一段时间后遇到了问题(“突然”)。
这是有帮助的(ab******-解决方案,但问题仅出现在 devMode 中,并通过此解决):
I had the problem after a time using the persistence-unit ("suddenly").
here's what helped (a b******-solution, but the problem occurs only in devMode and is solved with this):
这有效...
This works...
如果您的其他 jar 位于类路径中,您应该能够使用以下命令加载此文件:
getClass().getResourceAsStream("META-INF/persistence.xml");
If your other jar is in the classpath, you should be able to load this file using:
getClass().getResourceAsStream("META-INF/persistence.xml");