Do I need to include EclipseLink modelgen package in my Maven dependencies?

怎甘沉沦 提交于 2019-12-11 17:14:33

问题


I am using Netbeans 7.1 to write a Maven-built JSF 2.0 web application. The server is GlassFish 3.1, and EclipseLink as a JPA 2.0 provider.

When I do a "clean and build" of the project, all the generated sources for the JPA meta-model go away and don't come back. So Netbeans sees piles of undefined symbols. Red dots everywhere.

The odd thing is, if I run the project, the meta-model somehow gets generated then, and eventually finds its way back to the generated-sources directory that the Maven project uses. The web app runs. But there is no way to generate the meta-model without running the application. Sometimes it takes several passes!

By experimenting around I discovered that if I include the following as a dependency, the problem partly goes away. The clean-and-build still generates errors in the output, but the model is generated as far as the IDE is concerned.

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
        <version>2.3.0</version>
    </dependency>

Can someone explain what is going on, and perhaps what I should be doing?


回答1:


I am using the following dependency:

<dependency>
  <groupId>org.eclipse.persistence</groupId>
  <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
  <version>2.5.2</version>
  <scope>provided</scope>
</dependency>

After a 'clean and build' you will see that the meta model does get built at build time and the classes are in fact included in the target/generated-sources/annotations folder. These then get put into the jar file. So that being said you can scope these as "provided" so it gets used during build time but not included in the overall distributed package.




回答2:


If I understand correctly processor generate meta-model when application starts (at runtime). So you have to include it to your web application.

Meta model classes does not exist before.



来源:https://stackoverflow.com/questions/9776595/do-i-need-to-include-eclipselink-modelgen-package-in-my-maven-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!