mar*_*bol 8 maven-2 unit-testing jar classloader dependency-management
我编译我的程序对javaee-api.但是对于Junit测试,我必须使用像glassfish的javaee.jar这样的特定实现来避免像java.lang.ClassFormatError这样的错误:在类文件javax/persistence/Persistence中不是本机或抽象的方法中的Absent Code属性(另请参见1).
因此,请避免使用仅在glassfish实现中可用的方法,我想使用常规api编译我的工件,但是使用实现jar运行junit.但两者都提供相同的命名类和推理,因此类加载器遇到麻烦.
解决这个问题的最佳方法是什么?我可以用maven解决这个问题吗?
非常感谢
Pas*_*ent 13
我认为这是可能的.实际上,从版本2.0.9开始,Maven使用POM命令来构建类路径,因此您现在可以对其进行操作.如果将此与依赖范围相结合,应该可以实现您想要的目标.实际上,如果将GlassFish的javaee依赖项(带有测试作用域)放在依赖项之前javaee-api,前者应该放在测试类路径中的后面,然后由单元测试使用,而后者将在编译期间使用.从理论上讲,这应该有效,但它有点脆弱,因此需要仔细记录.
类似的东西(带有虚构的GFv3 jar):
<dependencies>
<dependency><!-- this one will be first on the test classpath -->
<groupId>org.glassfish</groupId>
<artifactId>javaee</artifactId>
<version>6.0</version>
<scope>test</scope>
<dependency>
<dependency><!-- this one will be used during compile -->
<groupId>javax.javaee-api</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
<dependency>
...
</dependencies>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3088 次 |
| 最近记录: |