There is an application compiled in Java 6. You need to call from it a class method from jar that is compiled in Java 7. When you try to do this, we get an error

- java.lang.UnsupportedClassVersionError: ... : Unsupported major.minor version 51.0. 

That is, do not correspond to the version. Is it possible to call from java6 jar to java7? And if not, in which direction is it best to move? Upgrade / downgrade is not possible. The java6 application is spinning on tomcat. What other options to build interaction? Servlet, rmi, call from java bat file, etc? Which option is simpler and more reliable?

  • one
    The last question (optional) is too wide for the Stack Overflow format. There is no better option for the general case, otherwise there would not be so many options. The tool is chosen according to the situation, given the experience. - default locale

2 answers 2

There are 3 ways:

  1. Recompile Java 7 project under Java 6.

    Plus : if the features of version 7 are missing or few, very quickly.

    Minus : if the features of Java 7 are many to remove them for a long time and the support of two versions of the language may require a lot of power, well, the pre-upgrade to the old and not reliable version is not very good.

  2. Try running a Java 6 project on JRE7 (it is not necessary to compile, just run). In Java, good support for backward compatibility and problems often will not, just in case, read the documentation about compatibility of different versions .

    Plus : if everything is fine, it takes almost no time.

    Minus : in a large and complex system on the new version, something unexpectedly can break at runtime (there have been cases). Plus, in the right way, it is desirable to conduct a full regression test of the entire large system, and this can be a very expensive pleasure.

  3. Connect systems not as jar, but through any integration methods (rest services, message queues, files on disk, shared memory, or other program communication methods). In addition, each system can run on its own version of Java, either under different virtual machines or docker containers or even different servers. It may be necessary for integration to write small modules for each system.

    Plus : there will be a more microservice approach and less chance that something will break,

    Minus : additional costs for integration.

    To do this, the java6.jar application needs to be run from under Java 7. But incompatibilities are possible (especially if reflections are used).

    UPD. Another option is to rebuild the java7.jar application for Java 6.

    • one
      Unfortunately, the java6.jar application is a monster. There is no readiness to test its recompilation on java7 or running under java7. But an interesting move. - Orthodox
    • one
      It is not necessary to recompile, as a rule, it is enough just to run under the new version of the JRE. I came across incompatibility only when using reflections, but functional testing does not hurt. - Michael Belyakov
    • one
      Rebuilding java7.jar under java 6 is impossible - Orthodox
    • one
      You can also come up with crutches like RMI . That is, to keep one application for Java 6, another for Java 7, but the amount of changes in the code can be significant. I must say that I have not tried this option in practice. - Michael Belyakov
    • Yes, you can even make additional mini-applications for integration. - Viacheslav Vedenin