由于
,我遇到了运行可运行jar的麻烦HHH000318: Could not find any META-INF/persistence.xml file in the classpath
目录结构:
JAR META-INF / Manifest内容:
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: .
从root运行命令:
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>
答案 0 :(得分:1)
尝试添加pom.xml
<resources>
<resource>
<directory>path_to_your_resource_folder</directory>
<filtering>true</filtering>
</resource>
</resources>
path_to_your_resource_folder是项目文件夹路径中包含persistence.xml的目录路径。 我建议你创建一些像src / main / resources这样的目录,然后在这里粘贴persistence.xml。然后path_to_your_resource_folder = src / main / resources