Fundamentals 7 min read

Understanding Java 8 Compact Profiles (JEP 161) and Their Usage with jdeps

The article explains Java 8's compact profiles introduced by JEP 161, their benefits for resource‑constrained devices, how to compile and profile applications with javac and jdeps, and provides practical build commands and size comparisons for IoT‑oriented Java runtimes.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
Understanding Java 8 Compact Profiles (JEP 161) and Their Usage with jdeps

Oracle released Java 8, which includes JEP 161 that defines compact profiles (compact1, compact2, compact3) allowing applications to run on a reduced JRE that consumes fewer resources, starts faster, improves security by removing unused code, and reduces download size.

Benefits

Smaller Java environment requires less compute resources.

Reduced runtime can improve performance and startup time.

Eliminating unused code enhances security.

Packaged applications download faster.

Concept

Compact profiles are hierarchical (compact1 < compact2 < compact3) and each includes a specific subset of the Java API.

To compile against a profile, use the javac –profile <profile> option. If the code uses APIs not present in the selected profile, compilation fails, as shown in the example error output:

javac -profile compact2 Test.java
Test.java:7: error: ThreadMXBean is not available in profile 'compact2'
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
^
Test.java:7: error: ManagementFactory is not available in profile 'compact2'
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
^
2 errors

Using the jdeps tool

Java 8 adds the jdeps utility to analyze which profile an application requires. Common options are -p, -v, and -R:

import java.util.Set;
import java.util.HashSet;

public class Deps {
    public static void main(String[] args) {
        System.out.println(Math.random());
        Set<String> set = new HashSet<>();
    }
}

Running jdeps produces detailed output, for example:

************** PROFILE ********************
jdeps -P Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
<unnamed> (Deps.class)
    -> java.io                                            compact1
    -> java.lang                                          compact1
    -> java.util                                          compact1

************** VERBOSE ********************
jdeps -v Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
Deps (Deps.class)
    -> java.io.PrintStream
    -> java.lang.Math
    -> java.lang.Object
    -> java.lang.String
    -> java.lang.System
    -> java.util.HashSet

************** RECURSIVE ********************
jdeps -R Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
<unnamed> (Deps.class)
    -> java.io
    -> java.lang
    -> java.util
    ... (additional internal JDK APIs omitted for brevity)

Building compact profiles on Linux

$ hg clone http://hg.openjdk.java.net/jdk8/jdk8/
$ cd jdk8
$ make images profiles
## Finished profiles (build time 00:00:27)
... (build time breakdown)
$ cd images
$ ls -d *image
j2re-compact1-image j2re-compact2-image j2re-compact3-image j2re-image j2sdk-image

The resulting compact JRE images occupy significantly less disk space, making them suitable for IoT devices. Oracle has also released a Raspberry Pi‑specific JRE.

Conclusion

Compact profiles provide a lightweight Java runtime that meets the resource constraints of modern IoT devices and prepares developers for Java 9 modularization, offering a path toward more modular and maintainable applications.

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.

javaIoTCompact ProfilesjdepsJEP 161
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

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.