构建 Java EE 6 项目时出现 FilerException
我在 Netbeans 7 中有一个 Java EE 6 项目,当我在 IDE 中编译并启动它时,该项目运行良好。但是,当我清理和构建项目时,我得到了
java.lang.RuntimeException
:javax.annotation.processing.FilerException
:尝试重新创建类型为 {myclass
}
(其中 myclass
始终是 JPA 实体类)。
如果我更改代码中的某些内容,它会更改哪个实体类。
我不知道什么可能导致此错误 - 任何人都可以提供查看内容的想法。
我使用的唯一额外库是 Velocity。
更新:我在同一个数据库上使用两个持久性单元,一个是“正常”持久性单元,一个是非事务性持久性单元。我用非事务性的方式将内容记录到数据库中;每次插入日志事件后都会提交一次。
当我更改它并仅使用一个“正常”PU 时,该项目可以正常编译。难道这两个 PU 干扰了 eclipselink 所做的某些优化?
这是堆栈跟踪的开头:
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type de.guj.contenthub.ftdts.entity.AgofEntry_
at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:407)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:625)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:554)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:699)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981)
at com.sun.tools.
I have a Java EE 6 Project in Netbeans 7 which runs fine when I compile and start it in the IDE. However, when I clean and build the project, I am getting a
java.lang.RuntimeException
:javax.annotation.processing.FilerException
: Attempt to recreate a file for type {myclass
}
(where myclass
is always a JPA entity class).
Which entity class it is changes if I change something in the code.
I have no clue what might cause this error - can anyone provide an idea what to look at.
The only extra lib I am using is Velocity.
Update: I am using two persistence units on the same database, one 'normal' one and one non transactional one. The non-transactional one I use for logging things to the database; with a commit after each insert of a log event.
When I change that and only use the one 'normal' PU, the project compiles fine. Could it be that the two PUs interfere with some optimization done by eclipselink?
Here is the beginning of the stack trace:
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type de.guj.contenthub.ftdts.entity.AgofEntry_
at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:407)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:625)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:554)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:699)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981)
at com.sun.tools.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
使用相同实体类的两个持久性单元似乎确实是问题所在。
就我而言,我有一个单元用于查询数据,另一个单元用于身份验证。用于身份验证的不需要了解我的实体类,因此在 Netbeans 中我必须取消选中“在“MyWebServiceProject”模块中包含所有实体类”。
或者添加:
到该持久性单元的 web.xml 文件。
Having two persistence units using the same Entity class did seem to be the problem.
In my case I had one unit for querying data and the other for authentication. The one for authentication does not need to know about my Entity classes, so in Netbeans I had to uncheck the "Include All Entity Classes in "MyWebServiceProject" Module".
Or add:
to the web.xml file for that persistence unit.
解决了这个问题
我通过在 persistence.xml 中设置每个持久性单元 。每个单元的值必须是唯一的。然后将这些类生成到不同的包中,例如。
com.mycompany.foo.PojoOne_
和com.mycompany.bar.PojoOne_
而不仅仅是com.mycompany.PojoOne_
。来源
I got this solved by setting
for each persistence unit in persistence.xml. The value has to be unique for each unit. The classes are then generated into different packages, eg.
com.mycompany.foo.PojoOne_
andcom.mycompany.bar.PojoOne_
instead of justcom.mycompany.PojoOne_
.Source
答案是在 persistence.xml 文件中进行此操作;
例如,entity1 的包将生成为:
The answser is to make this in the persistence.xml file;
For example, the packages for the entity1 will be generated as :
看来,问题是我在两个不同的持久性单元中使用同一个实体类。我不确定这是否被 JPA 一般禁止,或者只是 eclipselink 的问题。
我发现的一个“解决方案”是复制我的实体类。不太好,但目前可以使用。
仍然欢迎更多答案。
It seems, the problem is that I use one and the same entity class in two different persistence units. I am not sure whether this forbidden by JPA in general or is only a problem with eclipselink.
One 'solution' I found then is to duplicate my entity class. Not nice, but works for now.
More answers still welcome.
我遇到了同样的问题,并且已经对其进行了一些诊断,以至于我有一个不理想的丑陋解决方法。
我的 persistence.xml 中有两个持久性单元:一个用于测试,一个用于实际的生产构建。
我这样做的原因是因为如果我使用将另一个 persistence.xml 放在 src/tests/resources/META-INF 文件夹下的首选方法,测试会失败,因为生成的类被放入 target/ generated-sources/ 中test-annotations 文件夹,并且编译后不会出现在类路径中的正确位置。
问题是,如果两者都将“exclude-unlisted-classes”设置为 true,则 javac 编译器会尝试在编译器:编译期间重新创建注释类,当然在第二个 PU 上会失败,因为这些类已创建。
因此,为了使其正常工作,我将其中一个 PU 的“排除未列出的类”设置为 false,这让我生成了生成的元类,但测试失败了(因为 PU 不包含所需的实体)。
然后我将标志翻转回 true,并再次运行构建。由于类已经被编译,所以compile:compile不会运行,并且测试可以成功。
解决方法是 javac 编译器参数的 proc:none ,如下所述: http ://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
I'm having the same issue, and have diagnosed it a bit to the point that I have an ugly workaround that is not ideal.
I have two persistence units in my persistence.xml: one for testing and one for the actual production build.
The reason I have that is because if I use the preferred method of putting another persistence.xml under the src/tests/resources/META-INF folder, the tests fail because the generated classes get put in a the target/generated-sources/test-annotations folder and don't end up in the right place in the classpath once they compile.
The issue is that if both have the "exclude-unlisted-classes" set to true, the javac compiler tries to recreate the annotation classes during the compiler:compile and of course fails on the second PU because the classes have already been created.
So to get this to work, I set the "exclude-unlisted-classes" to false for one of the PU's, which gets me the generated meta classes, and the tests fail (because the PU doesn't include the required entities).
I then flip the flag back to true, and run the build again. Since the classes have already been compiled, the compile:compile doesn't run, and the tests can succeed.
Workaround was proc:none to the javac compiler args as described here: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
这个http://netbeans-org.1045718.n5。 nabble.com/entity-class- Generation-td5542168.html 为我解决了这个问题。只需将 -proc:none 添加到 NetBeans 中的编译器选项即可消除该晦涩的错误消息。
This http://netbeans-org.1045718.n5.nabble.com/entity-class-generation-td5542168.html solved it for me. Just adding -proc:none to the compiler options in NetBeans removed that obtuse error message.
使用
我只需要为我的 testPu 添加一个(用于 jUnit 测试的内存 Derby,而不需要实际使用 Glassfish / MySQL 安装)。这使得 testPU 在连接和子包方面与运行时 PU 不同,但在其他方面并不影响我的实体定义。
Using
I only needed to add one for my testPu (In memory Derby for jUnit tests, rather than needing to actually use Glassfish / MySQL installation). This made the testPU distinct from the Runtime PU in connection and subpackage, but otherwise did not affect my entity definitions.
手动包含每个持久性单元的实体类
不应在多个持久性单元中包含同一类。
include the entity classes for each persistence unit manually
should not include the same class in more than a persistence unit.
同一 persistence.xml 中的两个持久性单元可能使用相同的实体。因此,要么删除持久性单元之一,要么更改这两个单元访问的实体。
为此,请打开 persistence.xml 文件并向下滚动以查看您添加的其他单元。根据您的要求进行修改。
希望这有帮助。
Two persistence units within the same persistence.xml might be using the same entity. So either delete one of the persistence unit or change entities accessed by both the units.
To do this open persistence.xml file and scroll down to see another units that you've added. Modify it according to your requirements.
Hope this helps.
添加到 persistence.xml 文件行
Add to persistence.xml file line