2

I am using xjc ant task to generate java classes from xsd and wsdl and then i am generating a jar out of these generated classes. PFB the code i am using,

    <!-- Below code generates java classes from wsdl  -->
    <exec executable="xjc">
                <arg value="-wsdl" />
                <arg value="${wsdl}/mysample.wsdl" />
                <arg value="-d" />
                <arg value="${myclasses}" />
                 <arg value="-d" />
            <arg value="${myclasses}" />
            <arg value="${xsdfile}/mysample.xsd" />
     </exec> 

    <!-- Below code generates jar from java classes  -->
        <jar destfile="${jars}/mysample.jar" basedir="${myclasses}"/>

It works fine in my local with JDK7 but when i deploy it to my server which has jdk6 i am getting <pre>org.jboss.resteasy.spi.UnhandledException: java.lang.UnsupportedClassVersionError: com/my/webservices/mysampleweb. Any suggestion how to make this work??

EDIT: I am getting major version 51 is newer than 50, the highest major version supported by this compiler. error for some classes which were generated from xsd. How to resolve this??

I checked my ANT_HOME,java version and jre everything is fine.. But still i am getting the above error when build using ant via command line.. Any suggestion

ACP
  • 34,682
  • 100
  • 231
  • 371

1 Answers1

2

If you're building with Java version 7 and trying to run it on Java 6 - or really anything earlier than the version of Java you compiled with - you'll get this UnsupportedClassVersionError. Compiled Java bytecode is forwards-compatible with new releases of the JVM, but not backwards compatible. Put Java 7 on your runtime environment, or compile using JDK 6.

Specifically, from Oracle's documentation of the Java 7 release:

Binary Compatibility

Java SE 7 is binary-compatible with Java SE 6 except for the incompatibilities listed below. Except for the noted incompatibilities, class files built with the Java SE 6 compiler will run correctly in Java SE 7.

The class file version for Java SE 7 is 51, as per the JVM Specification, because of the invokedynamic byte code introduced by JSR 292. Version 51 class files produced by the Java SE 7 compiler cannot be used in Java SE 6.

Community
  • 1
  • 1
David
  • 2,602
  • 1
  • 18
  • 32
  • I am getting major version 51 is newer than 50, the highest major version supported by this compiler. error for some classes which were generated from xsd. How to resolve this?? – ACP Jul 19 '13 at 10:14
  • Are you getting that error on the server you've deployed the app to? If so, that machine needs to be running Java 7, OR you need to compile the app with Java 6. – David Jul 19 '13 at 14:08
  • The `-source` option tells javac what version of source files to accept. `-target` tells it to generate bytecode compatible with the specified version of the JVM, but that only works if you also specify the `-bootclasspath` and `-extdirs` options to point at the older version of Java's bootstrap classes. I think OP's problem _might_ be fixable by that mechanism, but it's better practice (library compatibility and such) to use the same JDK in development and deployment. – David Jul 25 '13 at 03:38