0

So here is the scenario, I am trying to compile a maven project which have some persistent classes. I have persistence.xml under src\main\resources\. This compiles fine, but I get run-time error for persistence not found which can be easily resolved if I manually move persistence.xml under META-INF dir of jar(xml file is packaged under root of the jar).

Now if I move persistence.xml under src\main\resources\META-INF I get weird compile-time error of

Fatal error compiling: java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type my.package.EntityClassName_

This EntityClassName can be any one of my Entity class.

I just want to package persistence.xml under META-INF directory of jar. Can someone point out what am I missing?

I am using maven compiler source and target as 1.6 if it matters.


EDIT: This project have a parent maven project.
  <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>
        <groupId>com.some.domain</groupId>
        <artifactId>p-parent</artifactId>
        <version>1.0.0</version>
        <packaging>pom</packaging>
        <modules>
            <module>m1</module>
            <module>m2</module>
            <module>m3</module>
        </modules>

        <properties>
            <maven.compiler.source>1.6</maven.compiler.source>
            <maven.compiler.target>1.6</maven.compiler.target>
        </properties>

        <scm>
            <connection>scm:git:https://some.place/project.git</connection>
        </scm>

        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.8.2</version>
                </dependency>
                <dependency>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>eclipselink</artifactId>
                    <version>2.6.0</version>
                </dependency>
                <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>1.2.16</version>
                </dependency>
                <dependency>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>javax.persistence</artifactId>
                    <version>2.0.0</version>
                </dependency>
                <dependency>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>org.eclipse.persistence.jpa.modelgen</artifactId>
                    <version>2.4.2</version>
                </dependency>
                <dependency>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc6</artifactId>
                    <version>11.1.0.6.0</version>
                </dependency>
            </dependencies>
        </dependencyManagement>

    </project>

pom of this project

<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.some.domain</groupId>
        <artifactId>p-parent</artifactId>
        <version>1.0.0</version>
    </parent>

    <artifactId>m2</artifactId>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa.modelgen</artifactId>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
        </dependency>

    </dependencies>

</project>
Noob
  • 27
  • 1
  • 5
  • (1) Putting `persistence.xml` under `src\main\resources\META-INF` is the right thing to do, you're simply getting a different error now that `persistence.xml` gets picked up properly, (2) could you post the `pom.xml`? – crizzis Mar 27 '18 at 14:13
  • @crizzis added pom as requested. The first one is parent pom, second one is of this project. – Noob Mar 27 '18 at 14:30
  • Well, the problem is clearly with the metamodel generation (it seems it is getting generated twice). I'd try switching to 'org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen. **processor** :2.6.0'. Also, the following answer might be helpful: https://stackoverflow.com/a/33035713/1092818. Are you using the metamodel in your project already? If not, I'd try removing the 'jpa.metamodel' artifact first to confirm that the problem goes away – crizzis Mar 27 '18 at 14:50

1 Answers1

0

It was solved bu using -proc:none as compiler argument.

Noob
  • 27
  • 1
  • 5