5

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:../
axtavt
  • 239,438
  • 41
  • 511
  • 482
GaDo
  • 146
  • 1
  • 7
  • odd, does the error always occur? Please include your persistence.xml. Is the JVM and OS the same as your Eclipse run? How are you running it? – James Dec 02 '10 at 16:07
  • 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! – GaDo Jan 07 '11 at 14:37
  • you should create an answer which you accept afterwards. – MRalwasser Jan 17 '11 at 11:26

6 Answers6

4

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!

GaDo
  • 146
  • 1
  • 7
  • Can you please explain in more detail how you fixed it – Kris Mar 04 '12 at 09:30
  • I can confirm it, selecting the option "Extract required libraries into generated JAR" in the "Runnable JAR file export" dialog solves the problem. Thank you. – joanlofe Jul 09 '12 at 20:52
  • Yes thanks Joanlofe..i was facing the same issue...Its resoved by changing the option to "Extract required libraries into generated JAR" – Iftikhar Ali Ansari Jan 20 '21 at 07:27
2

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.

rdguam
  • 356
  • 5
  • 10
  • Wow, this clears up for me why Eclipse always includes that into runnable jar files. Thanx man, even though it's been 10 years since your answer! – JayC667 May 06 '21 at 13:00
0

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.

col.panic
  • 2,944
  • 4
  • 25
  • 31
0

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.

Florent
  • 12,310
  • 10
  • 49
  • 58
Dimitri
  • 1
  • 1
0

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.

harshlal028
  • 1,539
  • 1
  • 16
  • 25
-1

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

Kris
  • 963
  • 1
  • 13
  • 22