gpt4 book ai didi

java - 使用可运行 jar 时未找到 persistence.xml

转载 作者:行者123 更新时间:2023-12-01 11:39:38 25 4
gpt4 key购买 nike

由于

,我在运行可运行的 jar 时遇到一些问题
HHH000318: Could not find any META-INF/persistence.xml file in the classpath

目录结构: enter image description here

JAR META-INF/ list 内容:

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 is not found

但它位于 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>

最佳答案

尝试在pom.xml中添加

<resources>
<resource>
<directory>path_to_your_resource_folder</directory>
<filtering>true</filtering>
</resource>
</resources>

path_to_your_resource_folderi 是项目文件夹路径中包含 persistence.xml 的目录的路径。我建议您创建一些目录,例如 src/main/resources 并将 persistence.xml 粘贴到此处。然后path_to_your_resource_folder= src/main/resources

关于java - 使用可运行 jar 时未找到 persistence.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29648956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com