0

Generally, I noticed that when my application's jar was compiled in a java version and running in some other java version the I get java.lang.UnsupportedClassVersionError exception.

But my application uses jars of log4j and tomcat etc...

  1. Use any version of java why don't I get such exception?
  2. Is it possible to make my application's jar to behave same way?
3
  • 5
    Isn't it only when you go back? That is, compile in 1.7, then try and run with a 1.6 runtime? A 1.7 runtime will happily run anything compiled with older ones...
    – Ash
    Commented May 20, 2013 at 11:34
  • I would probably just compile it for Java 7 and do something like this - try { ... } catch (UnsupportedClassVersionError e) { DisplayMessage("This application unfortunately only works on Java 7 and above. Please visit ... to install the latest version of Java."); }. Commented May 20, 2013 at 11:37
  • @G.S: This question may be of use, working out what compiler version a particular class was compiled with: stackoverflow.com/questions/1096148/…
    – Ash
    Commented May 20, 2013 at 12:05

1 Answer 1

1

This exception is thrown if JVM does not support class version you sent it, i.e. if at least one of your classes is compiled by compiler of higher version that version of you JVM.

So, check it. Is there a chance that you compile your classes with compiler of version 1.7 and run them on 1.6?

I believe that log4j and tomcat should not cause problem because I think that they still are compiled for jvm 1.6. Take a look on command line option -target that allows generating classes of specific version even if compiler's version is higher.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.