I created a Jar with Java 6. Now I'm creating a release document and recording the dependencies. How can I find the earliest version of Java that can successfully run the Jar, and the earliest version of Java that can successfully compile the source into a Jar?
2 Answers
I only know a manuel solution: try it out. There are, however, two things to consider.
- For which version is the code language compatible?
- For which JRE will it execute?
The first you can do with your current JDK, just iterate over the -source
and -target
arguments which you pass to your javac
compiler. This will, however, not prevent you from using classes and methods from the JDK you are using. If you do, the code will not execute for a lower JRE, if you are using classes or methods that where not present back then.
The savest way would be to install all different JDKs along and try to compile the code with each of their compilers.

- 27,743
- 15
- 106
- 143
-
1Unfortunately, AFAIK, I think this will not prevent you from using API features that are not part of a given JDK distribution. For instance, supposing you're compiling with a JDK 1.7 compiler, you could use `-source 1.5` `-target 1.5` and the compiler still would not complain that you are using the method `String.isEmpty()` which was added in JDK 1.6 – Edwin Dalorzo Jul 03 '12 at 18:28
-
@EdwinDalorzo Exactly! I was just about to add that. – Konrad Reiche Jul 03 '12 at 18:30
-
In this case then I am not sure that this approach is of great help, given the fact that the question is about checking dependencies, and the source and target command line options only serve to check language-feature compatibility. – Edwin Dalorzo Jul 03 '12 at 18:33
-
@EdwinDalorzo I agree, I see then only to install all different JDKs as a possible solution, unless there is a tool doing that. – Konrad Reiche Jul 03 '12 at 18:38
If you created the jar with java 6 and did not specify a different version of output bytecode, the generated class files will require Java 6 or greater. You can experiment to see what versions of bytecode you can generate with your source with the -target
command line option if you're compiling manually, if you're using eclipse or some other IDE, most have settings that control the generated bytecode version in project options or somewhere similar.
A related post about determining the bytecode versions of class files: What version of javac built my jar?