Hi there,
We're writing a standalone Java application that uses the Eclipselink JPA 2 provider for its data persistence. We wanted to pack it using one-jar, but when we execute it, we get the following exception at runtime:
Internal Exception: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: com.simontuffs.onejar.JarClassLoader@61de33
Internal Exception: java.io.FileNotFoundException: \lib\our-app-SNAPSHOT.jar (Das Systemkann den angegebenen Pfad nicht finden)
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:133)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:65)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.mycompany.myapp.MyAppImpl.initialize(MyAppImpl.java:62)
at com.mycompany.myapp.MyAppImpl.doRun(MyAppImpl.java:79)
at com.mycompany.myapp.MyAppImpl.run(MyAppImpl.java:67)
at com.mycompany.myapp.MyApp.run(MyApp.java:34)
at com.mycompany.myapp.MyApp.main(MyApp.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: com.simontuffs.onejar.JarClassLoader@61de33
Internal Exception: java.io.FileNotFoundException: \lib\our-app-SNAPSHOT.jar (Das Systemkann den angegebenen Pfad nicht finden)
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:221)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:134)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:125)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:98)
... 13 more
Caused by: java.io.FileNotFoundException: \lib\our-app-SNAPSHOT.jar (Das System kann den angegebenen Pfad nicht finden)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
at java.util.jar.JarFile.<init>(JarFile.java:135)
at java.util.jar.JarFile.<init>(JarFile.java:99)
at org.eclipse.persistence.internal.jpa.deployment.ArchiveFactoryImpl.createArchive(ArchiveFactoryImpl.java:82)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:213)
... 16 more
Our filesystem looks like this:
cwd/
|-- bin/ <= here's the wrapping shellscript in which we execute the java call
|-- lib/ <= this is where the one-jar-built Jar (our-app-SNAPSHOT.jar) resides.
It looks like an issue with the OneJar classloader, maybe you have an idea?
Best regards,
Mike
It's hard to tell what's up from the exception trace. Which version of One-JAR? If you can isolate the problem down to a minimal build.xml example I'll take a look.
Regards,
Simon.
Same problem, using onejar maven plugin 1.4.4 and onejar 0.97 and lates eclipselink.
It seems that eclipselink asks classloaders to search perhaps persistence.xml in all archives on classpath, but ...
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: com.simontuffs.onejar.JarClassLoader@35071f57
Internal Exception: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: com.simontuffs.onejar.JarClassLoader@35071f57
Internal Exception: java.io.FileNotFoundException: /./cis-db-sync.jar (Adresář nebo soubor neexistuje)
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:118)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at cz.i.cis.syncdb.Main.main(Main.java:53)
... 6 more
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: com.simontuffs.onejar.JarClassLoader@35071f57
Internal Exception: java.io.FileNotFoundException: /./cis-db-sync.jar (Adresář nebo soubor neexistuje)
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:321)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:272)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:150)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:135)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:76)
... 8 more
Caused by: java.io.FileNotFoundException: /./cis-db-sync.jar (Adresář nebo soubor neexistuje)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:214)
at java.util.zip.ZipFile.<init>(ZipFile.java:144)
at java.util.jar.JarFile.<init>(JarFile.java:152)
at java.util.jar.JarFile.<init>(JarFile.java:116)
at org.eclipse.persistence.internal.jpa.deployment.ArchiveFactoryImpl.createArchive(ArchiveFactoryImpl.java:93)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:297)
... 12 more
Sorry for czech localization, "Adresář nebo soubor neexistuje" means "Directory or file does not exist".
I think the whole problem is resolving files by classloader - it creates invalid URL, missing // , for example:
bad: file:/tmp/something.jar
good: file:///tmp/something.jar
I still cannot find the source of this bug, because every classpath resolution is processed by classloader ... but if this would be fixed, it would close many other issues ... :-)
The last comment is not true.
It seems it is EclipseLink's problem when persistence.xml file is not accesible directly in filesystem or network ...
https://bugs.eclipse.org/bugs/show_bug.cgi?id=287718
I will try to find some "nice" solution ...
I GOT IT! :)
From the main method I set this JVM option:
System.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML,
"main/cis-db-sync-0.0.1-SNAPSHOT.jar!/META-INF/persistence.xml");
- it is relative path of persistence.xml in onejar file, so I think if I change it to some configurable item, it will work without EclipseLink's presistence.xml autosearch.
If that doesn't work, the "semi-nice" solution would be to use the One-Jar-Expand mechanism (documented) to expand the persistence.xml file out of the jar into the file-system underneath your user.dir location (or into /tmp). As much as this goes against the goal of One-JAR which is to "not pollute your filesystem", sometimes you just have to. By specifying the file in this manifest property you should be able to force EclipseLink to find it.
It works perfectly:
[EL Info]: 2013-01-15 10:23:39.441--ServerSession(263788122)--EclipseLink, version: Eclipse Persistence Services - 2.4.1.v20121003-ad44345
[EL Info]: connection: 2013-01-15 10:23:40.317--ServerSession(263788122)--jar:file:/home/dmatej/work/repo/git/cis-master-glassfish/ext-java/cis-db-sync/target/cis-db-sync.jar!/main/cis-db-sync-0.0.1-SNAPSHOT.jar_PrimaryDatabase_url=jdbc:informix-sqli://host.cz:1525/cis:INFORMIXSERVER=cisdb;DELIMIDENT=y;CLIENT_LOCALE=cs_cz.912@sis;_user=cis login successful
I think you can close this issue, because it is not problem of OneJar but EclipseLink as seen in their Bugzilla. This workaround (setting JVM option, path to persistence.xml, even relative) is probably even desired due to performance, because then is not needed to perform automatic search of persistence.xml file.