我正在編寫一個獨立的java應用程序,從Maven項目構建它並通過調用jar文件執行。持久性單元被覆蓋
在我有使用持久性單元,在我的persistence.xml定義是獨立的(交易類型=「RESOURCE_LOCAL」)
實際實體註解的類的實體管理應用來自另一個項目,並且因此作爲依賴項添加到pom.xml文件中。
問題是,包含實體類的項目的persistence.xml會在生成jar包的目標文件夾時覆蓋實際的獨立應用程序的persistence.xml。
Maven構建過程中經歷成功,但在運行罐子時,我得到這樣一個例外:
異常線程「main」 javax.persistence.PersistenceException:沒有 持久性提供適用於「PersistenceUnitXXX」試圖 後以下發現實現: org.eclipse.persistence.jpa.PersistenceProvider
另外包含實體類項目的持久性單元是指FO部署在應用程序服務器上,所以我認爲不可能爲獨立應用程序重複使用persistence.xml。
聚甲醛是這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.my</groupId>
<artifactId>projects</artifactId>
<version>1.0</version>
<relativePath>../..</relativePath>
</parent>
<groupId>com.my.projects</groupId>
<artifactId>mystandaloneapp</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.oracle.weblogic</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.3-0-0</version>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0-5</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20170516</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.my</groupId>
<artifactId>my_entities</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.my.StandAloneApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>create-my-bundle</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>eksport-assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
文件結構是
-projects
-mystandaloneapp
-src
-main
-java
-com
-my
-db
-EntityConsumer
-resources
-WEB-INF
-persistence.xml
-my_entities
-src
-main
-java
-com
-my
-model
-db
-MyEntity
-resources
-WEB-INF
-persistence.xml
分享你的pom請 – Francesco
然後提一下文件la yout,因爲如果沒有這樣的信息,它會諮詢水晶球 –
用pom文件和文件結構更新。 –