I have taking an existing, old, Java code base and changed one class. I have recompiled the code base in Java 1.5.0. I then successfully deploy this code on Tomcat.
As you probably run java indirectly from the command line, ant or maven, it depends on their java, javac and build scripts, and variables therein. Maven is uncomplicated; in Ant you can echo the java version should there be many includes.
To check the .class file, try the following. It is Java 7, but easily translatable to an earlier version.
private static void dumpJavaClassVersion(String path) throws IOException {
File file = new File(path);
try (InputStream in = new FileInputStream(file)) {
byte[] header = new byte[8];
int nread = in.read(header);
if (nread != header.length) {
System.err.printf("Only %d bytes read%n", nread);
return;
}
if (header[0] != (byte)0xCA || header[1] != (byte)0xFE
|| header[2] != (byte)0xBA || header[3] != (byte)0xBE) {
System.err.printf("Not a .class file (CAFE BABE): %02X%02X %02X%02X",
header[0], header[1], header[2], header[3]);
return;
}
int minorVs = ((header[4] & 0xFF) << 8) | (header[5] & 0xFF);
int majorVs = ((header[4] & 0xFF) << 8) | (header[5] & 0xFF);
final String[] versionsFrom45 = {"1.1", "1.2", "1.3", "1.4", "5", "6", "7", "8", "9", "10"};
int majorIx = majorVs - 45;
String majorRepr = majorIx < 0 || majorIx >= versionsFrom45.length ? "?" : versionsFrom45[majorIx];
System.out.printf("Version %s, internal: minor %d, major %d%n",
majorRepr, minorVs, majorVs);
}
}