我写了一个除了JAX-RS和包括Java EE 6 API作为Maven依赖。
javax
javaee-api
6.0
provided
然后我有一个小测试用例:
@Test
public void testIsWriteable() {
class SpecialViewable extends Viewable {
public SpecialViewable() {
super("test");
}
}
FreeMarkerViewProcessor processor = new FreeMarkerViewProcessor(null);
assertTrue(processor.isWriteable(SpecialViewable.class, null, null,
MediaType.WILDCARD_TYPE));
}
但我得到一个错误:
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/MediaType
...
如果我将Jersey包括为JAX-RS实现而不是Java EE API,一切都很好。
感谢BalusC的提示我知道我猜到了:Java EE 6只是一个没有方法主体的API:
From the java.net blog
You can compile you code with this
jar, but of course you cannnot run
your application with it since it
contains only the Java EE 5 APIs and
does not contain any method bodies. If
you try to run, you would get this
exception:
Exception in thread “main”
java.lang.ClassFormatError: Absent
Code attribute in method that is not
native or abstract in class file
javax/mail/Session
In order to execute a Java EE 5
application, you’ll still need a Java
EE 5 container, like for example the
GlassFish application server.
我试图添加Jersy与测试范围,但它没有工作。
javax
javaee-api
6.0
provided
com.sun.jersey
jersey-server
${jersey-version}
test
如何测试仅依赖于官方Java EE API的软件?
解
提供程序(Jersey)需要放在pom.xml中的API(javeee-api)之前。
com.sun.jersey
jersey-server
${jersey-version}
test
javax
javaee-api
6.0
provided