Example example_compile-target-jdk8

Part of the full Java 9 Jigsaw modules example suite.

Authors

Migrated for Java Modules support documentation of Apache MavenTM in the course of the Maven Support & Care program by Gerd Aschemann (and other team members) as forked repository. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original.

What is this example about?

This example is about compatibility of code compiled for jdk 8 / 9 and running it with jdk 8

Modules in this example

  • cpmain - classes on the classpath

Example shows …​

  • Code compiled with target JDK 8 runs with JDK 8.

  • Code compiled for target JDK > 8 does NOT run in JDK 8: The class version has changed.

To run this example, set a correct JDK 8 as environment variable JAVA8_HOME.

Note: No JavaDoc generation for this example.

Output

This example uses golden master testing to ensure output consistency. The expected output is compared with actual output using verify.sh.

Expected Output

Simple test to find out if code compiled with a JDK >8 runs with JDK8. If you see this output, the call worked!
Simple test to find out if code compiled with a JDK >8 runs with JDK8. If you see this output, the call worked!
Exception in thread "main" java.lang.UnsupportedClassVersionError

Actual Output

Simple test to find out if code compiled with a JDK >8 runs with JDK8. If you see this output, the call worked!
Simple test to find out if code compiled with a JDK >8 runs with JDK8. If you see this output, the call worked!
Exception in thread "main" java.lang.UnsupportedClassVersionError

Maven 4 Migration

This example does not include a Maven 4 migration variant (m4/ directory) because it is primarily about demonstrating compatibility with older JDK 8 code, not about Java Modules.

The example focuses on cross-compilation targeting JDK 8, which is independent of Maven version. Since the migration to Maven 4 in this repository focuses on Java Modules-related features, and this example doesn’t rely on Java Modules, there is no need for a separate Maven 4 migration demonstration here.