eclipselink 可执行 JAR 中的 PersistenceUnitLoadingEception

发布于 2024-10-05 16:11:09 字数 5187 浏览 1 评论 0原文

我正在开发一个使用 eclipselink 的独立 java 应用程序。当我从 eclipse IDE 执行应用程序时一切都很好。但我已经导出了一个可执行 JAR 文件,从那以后我无法使 eclipseLink 工作。 我在 Eclipse 社区论坛此处发现了类似的问题,但还不太方便:

请帮忙,

我的例外情况如下:

01 dec. 2010 22:47:31,199  INFO Configuration:97 - Iniciate database
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:56)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.2.v
20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExcept
ion
Exception Description: An exception was thrown while searching for persistence a
rchives with ClassLoader: java.net.URLClassLoader@61de33
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services
- 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoad
ingExceptionException Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../
Internal Exception: java.net.MalformedURLException
        at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.ex
ceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126
)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:133)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:65)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:33)
        at eu.agilelabs.pillAgent.db.dam.DataManagerImplJPA.(DataManagerIm
plJPA.java:36)
        at eu.agilelabs.pillAgent.db.dam.DataManagerImplJPA.getInstance(DataMana
gerImplJPA.java:47)
        at eu.agilelabs.configuration.Configuration.(Configuration.java:98
)
        at eu.agilelabs.configuration.Configuration.getInstance(Configuration.ja
va:119)
        at eu.agilelabs.pillAgent.core.Main.main(Main.java:15)
        ... 5 more
Caused by: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.0.2.v
20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExcept
ion
Exception Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../
Internal Exception: java.net.MalformedURLException
        at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.ex
ceptionProcessingPersistenceXML(PersistenceUnitLoadingException.java:117)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceXML(PersistenceUnitProcessor.java:444)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceArchive(PersistenceUnitProcessor.java:401)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.getPersistenceUnits(PersistenceUnitProcessor.java:310)
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfoInArchive(JPAInitializer.java:149)
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfoInArchives(JPAInitializer.java:136)
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfo(JPAInitializer.java:125)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:98)
        ... 13 more
Caused by: java.net.MalformedURLException
        at java.net.URL.(Unknown Source)
        at java.net.URL.(Unknown Source)
        at java.net.URL.(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrent
Entity(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineD
ocVersion(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
nknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
nknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown So
urce)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Un
known Source)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.p
arse(Unknown Source)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceXML(PersistenceUnitProcessor.java:442)
        ... 19 more

我认为这一行一定是关键:

Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services
- 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoad
ingExceptionException Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../

I am developing a stand-alone java application which uses eclipselink. It is all fine when I execute the app from eclipse IDE. But I've exported an executable JAR file, and since than I can not make eclipseLink work.
I have found similar issue in the Eclipse community forum here, but yet not too handy:

Please help,

My exception is the following:

01 dec. 2010 22:47:31,199  INFO Configuration:97 - Iniciate database
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:56)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.2.v
20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExcept
ion
Exception Description: An exception was thrown while searching for persistence a
rchives with ClassLoader: java.net.URLClassLoader@61de33
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services
- 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoad
ingExceptionException Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../
Internal Exception: java.net.MalformedURLException
        at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.ex
ceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126
)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:133)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:65)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.
java:33)
        at eu.agilelabs.pillAgent.db.dam.DataManagerImplJPA.(DataManagerIm
plJPA.java:36)
        at eu.agilelabs.pillAgent.db.dam.DataManagerImplJPA.getInstance(DataMana
gerImplJPA.java:47)
        at eu.agilelabs.configuration.Configuration.(Configuration.java:98
)
        at eu.agilelabs.configuration.Configuration.getInstance(Configuration.ja
va:119)
        at eu.agilelabs.pillAgent.core.Main.main(Main.java:15)
        ... 5 more
Caused by: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.0.2.v
20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoadingExcept
ion
Exception Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../
Internal Exception: java.net.MalformedURLException
        at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.ex
ceptionProcessingPersistenceXML(PersistenceUnitLoadingException.java:117)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceXML(PersistenceUnitProcessor.java:444)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceArchive(PersistenceUnitProcessor.java:401)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.getPersistenceUnits(PersistenceUnitProcessor.java:310)
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfoInArchive(JPAInitializer.java:149)
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfoInArchives(JPAInitializer.java:136)
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPe
rsistenceUnitInfo(JPAInitializer.java:125)
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFa
ctory(PersistenceProvider.java:98)
        ... 13 more
Caused by: java.net.MalformedURLException
        at java.net.URL.(Unknown Source)
        at java.net.URL.(Unknown Source)
        at java.net.URL.(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrent
Entity(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineD
ocVersion(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
nknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
nknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown So
urce)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Un
known Source)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.p
arse(Unknown Source)
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProces
sor.processPersistenceXML(PersistenceUnitProcessor.java:442)
        ... 19 more

I think this line must be the key:

Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services
- 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.PersistenceUnitLoad
ingExceptionException Description: An exception was thrown while processing persistence.xml
from URL: rsrc:../

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

旧时模样 2024-10-12 16:11:09

我已经设法解决了它。我改变了eclipse导出jar文件的方式。如果它将所需的库提取到 jar 中,一切都会很好。不管怎样谢谢你!

I have managed to solve it. I changed the way eclipse exports the jar file. If it extracts required libraries into the jar everything works great. Thank you anyway!

め七分饶幸 2024-10-12 16:11:09

一些背景信息

正如您提供的链接所述,当 EclipseLink jar 嵌入到应用程序的 jar 中时,EclipseLink 似乎不支持加载 persistence.xml。

据我了解,标准的非定制 Java 不支持从嵌入式 jar 加载类的可运行 jar。 Eclipse 创建的可运行 jar 能够通过向应用程序的 jar 添加自定义类加载器 (org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader) 来克服该限制。显然,自定义类加载器是 EclipseLink 遇到此问题的地方。

话虽如此,在 Eclipse Helios 中,我发现“将所需的库复制到生成的 JAR 旁边的子文件夹中”比“将所需的库提取到生成的 JAR 中”更易于管理。

选择复制选项可以使 eclipselink jar 保持完整,而不是 Eclipse 提取各种 .class 文件并使应用程序的 jar 变得混乱。确实,您的应用程序将不再作为单个 jar 进行分发,但从可管理性的角度来看,这似乎比 extract-libraries 选项更好。

Some background info

As the link you've provided says, EclipseLink doesn't seem to support loading persistence.xml when the EclipseLink jar is embedded in your app's jar.

As I understand it, standard non-customized Java doesn't support runnable jars that load classes from embedded jars. The runnable jar that Eclipse creates is able to overcome that limitation by adding a custom classloader (org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader) to your app's jar. The custom classloader apparently is where EclipseLink runs into this issue.

With that said, in Eclipse Helios, I've found it more manageable to "Copy required libraries into a sub-folder next to the generated JAR" rather than to "Extract required libraries into generated JAR."

Choosing the copy option keeps the eclipselink jar intact, as opposed to Eclipse extracting the various .class files and cluttering your application's jar. True, your app will no longer be distributable as a single jar, but from a manageability standpoint, this seems better than the extract-libraries option.

甜警司 2024-10-12 16:11:09

我找到了相应的解决方案(即如果您没有使用 EclipseLink 2.3.2),正如 GaDo 在 Bug 364748,解决方案是将以下行添加到 MANIFEST.MF

Eclipse-BundleShape: dir

这会导致插件导出为目录而不是 JAR 文件,从而使 persistence.xml 可访问。

I found the respective solution (that is if you are not using EclipseLink 2.3.2), as mentioned by GaDo in Bug 364748, the solution is to add the following line into MANIFEST.MF

Eclipse-BundleShape: dir

This leads to the plug-in being exported as directory instead as JAR file, which makes persistence.xml accessible.

柠檬心 2024-10-12 16:11:09

我正在使用 EclipseLink 2.3.2 和 Eclipse Indigo,但仍然收到错误。

然后,像个傻瓜一样,我意识到我选择的是“将所需的库打包到生成的 JAR 中”而不是“将所需的库提取到生成的 JAR 中”。

不确定有什么区别,尽管我注意到我的一些 JAR 仅在我使用“需要包...”创建时才起作用,而其他 JAR 仅在我使用“需要提取...”创建它们时才起作用。

不知道为什么会这样。最终,我并不关心,只要生成的 JAR 没有外部依赖项即可。

顺便说一句,提出的另一个选项(修改 JAR 的清单文件)对我不起作用。我提取了manifext(jar xf MYJAR.jar META-INF/MANIFEST.MF),添加了Eclipse-BundleShape:dir,将其注入到jar中(jar umf META-INF/MANIFEST.MF MYJAR.jar),并验证清单是否已更改。同样的错误。

I was using EclipseLink 2.3.2, with Eclipse Indigo, and was still getting the error.

Then, like a fool, I realized that I was choosing "Package required libraries into generated JAR" instead of "Extract required libraries into generated JAR" works.

Not sure what the difference is, although I've noticed that some of my JARs only work when I create when using "Package required...", and others only work when I create them using "Extract required...".

Not sure why that is. Ultimately, I don't really care, as long as the resulting JAR has no external dependencies.

BTW, the other option that was proposed (modifying the JAR's manifest file) didn't work for me. I extracted the manifext (jar xf MYJAR.jar META-INF/MANIFEST.MF), added Eclipse-BundleShape: dir, injected it into the jar (jar umf META-INF/MANIFEST.MF MYJAR.jar), and verified that the manifest changed. Same error.

罗罗贝儿 2024-10-12 16:11:09

右键单击项目->属性-> Java 构建路径 ->订购并导出,然后选择库

右键单击项目 ->导出...->可运行的 JAR 文件 ->将所需的库复制到生成的 JAR 旁边的子文件夹中
这对我有用。

Right click on the project -> Properties -> Java Build Path -> Order and Export, and select the libraries

Right click on the project -> Export... -> Runnable JAR file -> Copy required libraries into a sub-folder next to the generated JAR
This worked for me.

梦里的微风 2024-10-12 16:11:09

此问题已在 EclipseLink 2.3.2 中修复
我升级了然后它就消失了

This issue has been fixed in EclipseLink 2.3.2
I upgraded and it went away

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文