使用wsgen和@Interceptors导致 - >不支持的major.minor版本51.0

时间:2013-10-18 10:13:54

标签: web-services maven java-ee interceptor wsgen

我有一个Java EE项目打包在耳朵上。 ear包含一个Jar,我将@stateless EJB和其他非托管类(我的模型,utils等)打包。对于其中一些EJB,我使用Jax-W将其功能公开为Web服务。

我尝试使用AOP创建日志记录机制,因此我将@Interceptors注释放在我的Jax-Ws驱动的EJB中。问题是,当我尝试使用maven编译/构建/打包时,我收到以下异常。似乎问题是特定于wsgen的原因,当我将@Interceptors注释放在NON Jax-ws带注释的EJB中时,它编译并运行没有任何问题。我使用JAva build 1.6.0_41-b02。

我还试图找到旧版本的javax.interceptor-api(可能是在Java 1.6中编译的,因为major.minor版本51.0意味着它已经在JSE 7中编译,如果我做对了)但似乎是1.2是旧的。

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:wsgen (MyWebService) on pro
ect my-ws-ejb: Failed to execute wsgen: javax/interceptor/Interceptors : Unsupported major.minor version 51.0 -> [Help
1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plu
in:2.2:wsgen (MyWebService) on project my-ws-ejb: Failed to execute wsgen
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to execute wsgen
        at org.jvnet.jax_ws_commons.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:148)
        at org.jvnet.jax_ws_commons.jaxws.MainWsGenMojo.execute(MainWsGenMojo.java:95)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: java.lang.UnsupportedClassVersionError: javax/interceptor/Interceptors : Unsupported major.minor version 51.

        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:249)
        at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
        at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
        at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
        at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
        at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:181)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
        at java.lang.Class.initAnnotationsIfNecessary(Class.java:3079)
        at java.lang.Class.getAnnotation(Class.java:3038)
        at com.sun.tools.ws.wscompile.WsgenOptions.validateEndpointClass(WsgenOptions.java:240)
        at com.sun.tools.ws.wscompile.WsgenOptions.validate(WsgenOptions.java:222)
        at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:123)
        at com.sun.tools.ws.WsGen.doMain(WsGen.java:74)
        at org.jvnet.jax_ws_commons.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:142)
        ... 22 more

我的pom(部分):

    <build>
            <!-- The name of the jar file -->
            <finalName>my-ws-ejb</finalName>
            <plugins>
                <!-- Use EJB 3.0 -->
                <plugin>
                    <groupId>org.apache.maven.plugins
                    </groupId>
                    <artifactId>maven-ejb-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <ejbVersion>3.0</ejbVersion>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jax-ws-commons</groupId>
                    <artifactId>jaxws-maven-plugin</artifactId>
                    <version>2.2</version>
                    <executions>
                        <!-- The WSDLs to be generated are placed here -->
                        <execution>
                            <id>MyWebService</id>
                            <configuration>
                                <sei>MyWebServiceBean</sei>
                                <genWsdl>true</genWsdl>
                                <keep>true</keep>
                                <verbose>true</verbose>
                            </configuration>
                            <goals>
                                <goal>wsgen</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                            <!-- Build with Java 6 -->
                            <source>1.6</source>
                            <target>1.6</target>
                            <!-- Show deprecations and warnings -->
                            <showDeprecation>true</showDeprecation>
                            <showWarnings>true</showWarnings>
                        </configuration>
                    </plugin>
            </plugins>
        </build>

        <dependencies>
            <!-- EJB 3 -->
            <dependency>
                <groupId>javax.ejb</groupId>
                <artifactId>ejb</artifactId>
                <version>3.0.1</version>
                <scope>provided</scope>
            </dependency>
            <!-- EclipseLink -->
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence</artifactId>
                <version>1.0.0.0_2-0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>persistence</artifactId>
                <version>1.0.0.0_2-0</version>
                <scope>provided</scope>
            </dependency>
            <!-- Oracle JDBC driver -->
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc6</artifactId>
                <version>11.1.0.7.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- AOP -->
            <dependency>
                <groupId>javax.interceptor</groupId>
                <artifactId>javax.interceptor-api</artifactId>
                <version>1.2</version>
            </dependency>
.....
</dependencies>

我的豆(部分)

@Interceptors(LoggingAopService.class)
@WebService(
        serviceName = "MyWebService", portName = "MyWebService",
        targetNamespace = "..."
)
@Stateless(name = "MyWebServiceBean", mappedName = "ejb/seb/MyWebServiceBean")
public class MyWebServiceBean implements MyWebService
{....}

3 个答案:

答案 0 :(得分:0)

您是否尝试web-beans.xml而不是annotation?如果没有,请检查this is link。可能是maven插件无法识别此注释。

类级声明应如下所示:

<myapp:MyWebServiceBean>
   <myfwk:LoggingAopService/>
</myapp:MyWebServiceBean>

这个拦截器需要启用:

<Interceptors>
    <myfwk:LoggingAopService/>
</Interceptors>

我没有测试这些代码。

答案 1 :(得分:0)

您发送的web-beans.xml声明是否特定于jboss?我使用Web逻辑,发现可以通过META-INF / beans.xml中添加的以下xml启用拦截器。

<interceptors>
    <class>org.samples.LoggingInterceptor</class>
</interceptors>

我将尝试xml声明,但因为我匆忙利用Jax-Ws框架本身提供的Handler功能(使用@HandlerChain注释)来“拦截”Web服务请求和响应。

答案 2 :(得分:0)

我还尝试使用@InterceptorBinding方式创建一个新的注释:

@Inherited
    @InterceptorBinding
    @Retention(RUNTIME)
    @Target({ METHOD, TYPE })
    public @interface Logging {
    }



@Interceptor
    @Logging
    public class LoggingInterceptor {
        @AroundInvoke
        public Object intercept(InvocationContext context) throws Exception {...}



 @Logging
    @WebService(serviceName = "MyWebService", portName = "MyWebService",
    targetNamespace = "...")
    @Stateless(name = "MyWebServiceBean", mappedName = "ejb/seb/MyWebServiceBean")
    public class MyWebServiceBean implements MyWebService
    {....}

但这也不能编译,我收到同样的错误:

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:w
sgen (EDocWebService) on project eDoc-ws-ejb: Failed to execute wsgen: javax/int
erceptor/InterceptorBinding : Unsupported major.minor version 51.0 -> [Help 1]

可能这是应该使用ejb-jar.xml的情况

    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
      <interceptors>
        <interceptor>
          <interceptor-class>com.mypackage.LoggingInterceptor </interceptor-class>
        </interceptor>
      </interceptors>

      <assembly-descriptor>
        <interceptor-binding>
          <ejb-name>MyWebServiceBean</ejb-name>
          <interceptor-class>com.package.Interceptor</interceptor-class>
        </interceptor-binding>
      </assembly-descriptor>
 </ejb-jar>