我正在使用Hibernate3开发JPA-2.0应用程序。它从eclipse运行良好,但如果从生成的runnable jar运行它,它会产生一个javax.persistence.PersistenceException:无法配置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)
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
如果我解压缩同一个jar,并直接运行该类,它可以工作:
java -cp .:<add list to all .jar files> MainClass
我无法弄清楚出了什么问题。
答案 0 :(得分:2)
如果在生成可运行的JAR时选择“将所需的库提取到生成的JAR中”,它将起作用。
答案 1 :(得分:0)
我首先要检查的一件事是persistence.xml位于你正在构建的jar的META-INF目录中。