Essential Guide to Migrating Java 8 Projects to Java 17: Compilation, Logging, and GC Tips

This article walks through the practical steps for upgrading Java 8 applications to Java 17, covering removed modules, annotation dependencies, sun.misc replacements, Lombok issues, Kotlin version limits, unified logging syntax, GC parameter changes, and runtime module‑open flags, while providing concrete Maven snippets and command‑line examples.

Programmer DD
Programmer DD
Programmer DD
Essential Guide to Migrating Java 8 Projects to Java 17: Compilation, Logging, and GC Tips

Compilation Related

JEP 320 – Removal of Java EE and CORBA Modules

Java 11 removed the Java EE and CORBA modules, so code that imports javax.annotation.* will fail to compile. Add the dependency manually:

<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.2</version>
</dependency>

Replacing sun.misc Packages

Classes such as sun.misc.BASE64Encoder are no longer available. Replace them with standard alternatives or update the library (e.g., Netty) that depends on them.

[ERROR]   symbol:   class BASE64Encoder
[ERROR]   location: package sun.misc

Lombok and com.sun.tools.javac Packages

Older Lombok versions use internal compiler APIs, causing errors like:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile … module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module

Upgrade Lombok to a recent version (e.g., 1.18.24) to resolve the issue.

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.24</version>
</dependency>

Kotlin Version Constraints

Kotlin versions prior to 1.6.0 cannot target Java 17. Upgrade Kotlin to at least 1.6.0 to compile against the new bytecode.

Analyzing Deprecated Dependencies

Use

jdeps --jdk-internals --multi-release 17 --class-path . encloud-api.jar

to list modules that need updating.

Dependency analysis output
Dependency analysis output

Parameter Migration

Unified Logging Overview

Java 9 introduced Unified Logging, replacing the old -Xloggc style GC logging with the unified -Xlog syntax. Example:

java -Xlog:gc=debug -version

Selectors follow the pattern <tag-set>=<level>. The default tag is all and level info, equivalent to java -Xlog:all=info -version.

To enable all GC tags at debug level:

$ java -Xlog:gc=debug -version
[0.023s][debug][gc] …

Wildcard * can be used for prefix matching, e.g., java -Xlog:gc*=debug -version.

List all available tags with java -Xlog:help.

GC Parameter Migration

Old GC flags are replaced by Unified Logging selectors: -XX:+PrintGCDetails

-Xlog:gc*
-XX:+PrintGC

-Xlog:gc
-Xloggc:<file>

-Xlog:gc:file=<file> Many deprecated flags (e.g., -XX:+PrintTenuringDistribution) are now covered by selectors such as -Xlog:gc+age=trace.

Recommended Unified Logging Configuration

-Xlog:
  // selections
    codecache+sweep*=trace,
    class+unload,
    class+load,
    os+thread,
    safepoint,
    gc*,
    gc+stringdedup=debug,
    gc+ergo*=trace,
    gc+age=trace,
    gc+phases=trace,
    gc+humongous=trace,
    jit+compilation=debug
  // output
  :file=/path_to_logs/app.log
  // decorators
  :level,tags,time,uptime,pid
  // output options
  :filesize=104857600,filecount=5

Runtime Related

Reflection and Private API Access

Since Java 9, accessing internal packages (e.g., sun.misc) requires --add-exports or --add-opens flags, such as:

--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
…

GC Algorithm Choices

CMS is deprecated; G1 is the default, while ZGC is experimental but may consume three times the RES memory due to its three‑view design.

G1 Tuning Tips

Avoid setting explicit young generation sizes ( -Xmn, -XX:NewSize, etc.) – let G1 manage them.

Adjust -XX:InitiatingHeapOccupancyPercent (default 45) to control when concurrent marking starts.

-XX:InitiatingHeapOccupancyPercent=55

}

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GC tuningjava-17Unified LoggingJava migrationJVM logging
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.