开发者

Java unsupported version -- Classic Problem

开发者 https://www.devze.com 2022-12-08 23:25 出处:网络
If you have 开发者_如何转开发ever used java I think at least one times you ever got error about unsupported version. Everybody known how to fixed it, change JRE and etc.

If you have 开发者_如何转开发ever used java I think at least one times you ever got error about unsupported version. Everybody known how to fixed it, change JRE and etc.

Today, I would like to know how to make jar file which can run any where (any JRE).


Short answer: Not possible.

Better answer: Define your minimum target (which really shouldn't be "any JRE"). Perhaps you mean "a standard J2SE 1.4 install" or "on android" (which isn't really a "JRE").

The exact minimum requirement is a combination of Java language features used, API and/or other library use (what where they compiled against?) and differences in different Java platforms. A DVD player is very much not like a desktop.


Im not so sure you would want that as a goal, most people these days target the Java 1.4+ platforms, meaning they will run on 1.5 and 1.6 as well, as and practically no-one uses any version of Java less than 1.4, you should be safe.

Having said that, its not totally impossible, just very hard, maintenance is a nightmare.


Even if you have that as a goal, you'll only be able to test on a subset. Depending on how comprehensive your auto-tests are, you'll probably want to define only a small set - maybe 6 or so - of properly supported JREs. If someone tries to run it on something else, well, it will probably work but you can't claim to have tested it.

If it's a GUI application this is more of a nightmare as testing GUIs is horrible. So you will want to support fewer JREs in this case.

Remember that you need to test a combination of JRE/OS, and that there are a lot of different OSs out there - at least a dozen different versions of Windows alone in common use (Not counting localisations).


If the application you are creating is programmed using Java 1.5 syntax, you may try using Retrotranslator. It uses bytecode manipulation to modify your classes and some runtime code that could allow your code to run with JVMs of version 1.4 and 1.3.

Of course, it has many limitations, but it supports many features from the 1.5 specification (extract from its website):

What Java 5.0 features are supported?

  • Generics
  • Annotations
  • Reflection on generics and annotations
  • Typesafe enums
  • Autoboxing/unboxing
  • Enhanced for loop
  • Varargs
  • Covariant return types
  • Formatted output
  • Static import
  • Concurrency utilities
  • Collections framework enhancements

By the end of the same page there are also some links to similar tools. But Retrotranslator seems to be the only one still actively maintained.


this error comes when your java class compiled in one version & run in another version.

0

精彩评论

暂无评论...
验证码 换一张
取 消