eclipselink PersistenceUnitLoadingEception in executable JAR

半世苍凉 提交于 2019-12-01 05:31:32

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!

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.

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

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.

Dimitri

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!