由于以下原因,我在运行可运行的 jar 时遇到了一些麻烦
HHH000318: Could not find any META-INF/persistence.xml file in the classpath
目录结构:
JAR META-INF/清单内容:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Antoniossss
Build-Jdk: 1.8.0_40
Main-Class: app.remote.Bootstrap
Class-Path: .
从根目录运行命令:
java -jar controller-1.0-jar-with-dependencies.jar
这导致
13:19:50.634 [main] DEBUG o.h.b.r.c.i.ClassLoaderServiceImpl - Incoming config yielded no classloaders; adding standard SE ones
13:19:50.637 [main] INFO o.h.j.b.i.PersistenceXmlParser - HHH000318: Could not find any META-INF/persistence.xml file in the classpath
13:19:50.638 [main] DEBUG o.h.jpa.HibernatePersistenceProvider - Located and parsed 0 persistence units; checking each
13:19:50.638 [main] DEBUG o.h.jpa.HibernatePersistenceProvider - Found no matching persistence units
13:19:50.639 [main] DEBUG o.h.b.r.c.i.ClassLoaderServiceImpl - Incoming config yielded no classloaders; adding standard SE ones
13:19:50.639 [main] INFO o.h.j.b.i.PersistenceXmlParser - HHH000318: Could not find any META-INF/persistence.xml file in the classpath
13:19:50.639 [main] DEBUG o.h.jpa.HibernatePersistenceProvider - Located and parsed 0 persistence units; checking each
13:19:50.640 [main] DEBUG o.h.jpa.HibernatePersistenceProvider - Found no matching persistence units
13:19:50.640 [main] DEBUG o.h.b.r.c.i.ClassLoaderServiceImpl - Incoming config yielded no classloaders; adding standard SE ones
13:19:50.641 [main] INFO o.h.j.b.i.PersistenceXmlParser - HHH000318: Could not find any META-INF/persistence.xml file in the classpath
13:19:50.641 [main] DEBUG o.h.jpa.HibernatePersistenceProvider - Located and parsed 0 persistence units; checking each
13:19:50.643 [main] DEBUG o.h.jpa.HibernatePersistenceProvider - Found no matching persistence units
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named registratorPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at
未找到 META-INF/perstistence.xml
但它在 META-INF 目录中。而且config.cfg
被正确读取,所以当前目录确实在类路径中。
对我来说奇怪的是以下命令运行得很好:
java -cp controller-1.0-jar-with-dependencies.jar; app.remote.Bootstrap
但是,如果我在 jar 名称后删除分号 (;),则错误与 jar 午餐尝试期间相同。
java -cp controller-1.0-jar-with-dependencies.jar app.remote.Bootstrap
有什么想法吗?jar 是用 maven 创建的
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>app.remote.Bootstrap</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>