0

I am new to writing ant scripts . I have code in Java 1.4 and when I compile the following ant script

<target depends="init" name="javacompile">
    <javac srcdir="${src}" destdir="${dest}" source="1.4" target="1.4"/>
</target>

I am getting an Unsupported major.minor version 49.0 Exception.

java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main (Unsupported major.minor version 49.0)

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
guitarist
  • 27
  • 2
  • 6

1 Answers1

0

The error is saying that your Ant script requires Java 1.4, but you're running JDK 5.0:

These are the mappings to major/minor numbers:

http://en.wikipedia.org/wiki/Java_class_file

J2SE 8 = 52 (0x34 hex),,
J2SE 7 = 51 (0x33 hex),
J2SE 6.0 = 50 (0x32 hex),
J2SE 5.0 = 49 (0x31 hex),
JDK 1.4 = 48 (0x30 hex),
JDK 1.3 = 47 (0x2F hex),
JDK 1.2 = 46 (0x2E hex),
JDK 1.1 = 45 (0x2D hex).

SUGGESTION:

Remove the source="1.4" target="1.4" qualifiers (if possible).

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • After removing the source="1.4" target="1.4" qualifiers also , I get the same error. I am using eclipse to run ant. I have set the compiler settings in project->properties Java compiler to 1.4 and also the build path has the 1.4 library. Is there any other setting required to be done. – guitarist Jul 05 '13 at 06:46
  • It definitely sounds like you have Java 1.5. Life would be Good if you could just allow the default Java version (instead of trying to force 1.4). Remember: newer JRE runtimes are backward-compatible with older classfiles/jarfiles. If you can't do that, then you *must* specify in your build and runtime paths a VALID INSTALLED JRE, and you must CONSISTENTLY use the same target flags in "ant" as well as all of your Eclipse settings. Also look here: http://stackoverflow.com/questions/7073485/why-is-ant-giving-me-a-unsupported-major-minor-version-error – paulsm4 Jul 05 '13 at 06:52
  • Thank you. I am using websphere5 and the ant script was using the java lib [Java version 5.0] from the websphere folder. I have pointed it back to 1.4 . Now it works. Thanks. – guitarist Jul 05 '13 at 07:21