开发者

Unable to configure EntityManagerFactory from runnable jar

I'm developing a JPA-2.0 application using Hibernate3. It runs fine from eclipse, but if run it from a generated runnable jar, it gives a javax.persistence.PersistenceException: Unable to configure EntityManagerFactory:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  开发者_StackOverflow社区  at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:374)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1937)
    at org.hibernate.ejb.packaging.JarVisitorFactory.getJarURLFromURLEntry(JarVisitorFactory.java:55)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:340)
    ... 12 more

If I unpack this same jar, and run the class directly, it works though:

java -cp .:<add list to all .jar files> MainClass

I cannot figure out what's wrong.


It'll work if you choose the "Extract required libraries into generated JAR" while generating the runnable JAR.


One thing i would check first is that the persistance.xml is in META-INF directory of the jar you are building.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜