Bug 266059 - java/openjdk*: Create x11 FLAVOR to support headless (no-x11) default
Summary: java/openjdk*: Create x11 FLAVOR to support headless (no-x11) default
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-java (Nobody)
URL:
Keywords: feature, needs-patch, needs-qa
Depends on:
Blocks: 266590
  Show dependency treegraph
 
Reported: 2022-08-27 06:08 UTC by Ryan Shaw
Modified: 2025-11-25 13:45 UTC (History)
7 users (show)

See Also:
bugzilla: maintainer-feedback? (java)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Shaw 2022-08-27 06:08:24 UTC
I am interested in a headless build of openjdk11 to use in a server environment but it seems there are no build configuration options available.

java/openjdk8 has --disable-headful to build a headless binary and a nice `make config` UI, but it seems the openjdk11 build is unconfigurable.

This is a request for a build configuration option for headless openjdk11. Thanks
Comment 1 Michael Osipov 2022-09-30 17:20:22 UTC
Won't work:
======================
...
checking how to link with libstdc++... static
configure: error: It is not possible to disable the use of X11. Remove the --without-x option.
configure exiting with result code 1
===>  Script "configure" failed unexpectedly.
Please report the problem to java@FreeBSD.org [maintainer] and attach the
"/var/tmp/freebsd-ports/java/openjdk11/work/jdk11u-jdk-11.0.15-10-1/config.log"
including the output of the failure of your make command. Also, it might be
a good idea to provide an overview of all packages installed on your system
(e.g. a /usr/local/sbin/pkg-static info -g -Ea).
*** Error code 1

Stop.
make: stopped in /var/tmp/freebsd-ports/java/openjdk11
======================

from:
./work/jdk11u-jdk-11.0.15-10-1/make/autoconf/libraries.m4:
======================
40 AC_DEFUN_ONCE([LIB_DETERMINE_DEPENDENCIES],
41 [
42   # Check if X11 is needed
43   if test "x$OPENJDK_TARGET_OS" = xwindows || test "x$OPENJDK_TARGET_OS" = xmacosx; then
44     # No X11 support on windows or macosx
45     NEEDS_LIB_X11=false
46   else
47     # All other instances need X11, even if building headless only, libawt still
48     # needs X11 headers.
49     NEEDS_LIB_X11=true
50   fi
======================
Comment 2 Sergey Fedorov 2024-05-05 22:49:05 UTC
(In reply to Michael Osipov from comment #1)

Headless should work, but it will still need some components of X11 to be installed.
Comment 3 Ronald Klop freebsd_committer freebsd_triage 2024-10-02 14:57:46 UTC
Openjdk11 and openjdk17 seems to have a new configure option --enable-headless-only. Didn't check openjdk21.

In this mail is talks about the introduction of this option:
https://mail.openjdk.org/pipermail/2d-dev/2016-August/007382.html

Openjdk11 pkg builds fine if I add CONFIGURE_ARGS+=--enable-headless-only to the port. I didn't check running it. And I didn't check how the dependencies of the openjdk11 need to change for an headless build.

Would it be enough to adapt these Makefile statements to the openjdk11 Makefile?
$ grep X11 /usr/ports/java/openjdk8/Makefile 
OPTIONS_DEFINE=         ALSA POLICY TZUPDATE X11 FONTCONFIG
OPTIONS_DEFAULT=        ALSA POLICY TZUPDATE X11
X11_BUILD_DEPENDS_OFF=  ${LOCALBASE}/include/X11/Xlib.h:x11/libX11 \
                        ${LOCALBASE}/include/X11/extensions/Xdbe.h:x11/libXext \
                        ${LOCALBASE}/include/X11/extensions/Xrender.h:x11/libXrender \
                        ${LOCALBASE}/include/X11/Intrinsic.h:x11-toolkits/libXt
X11_CONFIGURE_OFF=      --disable-headful
X11_CONFIGURE_ON=       --with-giflib=system \
X11_LIB_DEPENDS=        libgif.so:graphics/giflib
X11_MAKE_ENV_OFF=       BUILD_HEADLESS_ONLY=1 \
X11_USES=               xorg
X11_USE=                XORG=x11,xext,xi,xrender,xt,xtst
FONTCONFIG_IMPLIES=     X11


Anyway.. I have no personal interest in adding this to the port. As this issue is 2 years old I would like to know if the original requester is still interested or if other people know if this is still wanted?

Patches are welcome.
Comment 4 Michael Osipov freebsd_committer freebsd_triage 2024-10-02 15:02:11 UTC
I'd be happy to have this, but I won't pursue a patch. Maybe the reporter can work on a patch.
Comment 5 Ryan Shaw 2024-10-03 03:30:58 UTC
(In reply to Michael Osipov from comment #4)
Still interested! Just not familiar with makefiles enough to magic this together myself
Comment 6 Yonas Yanfa 2025-11-04 15:27:33 UTC
The OpenJDK v25 port added a headless flavor: https://reviews.freebsd.org/D53450

This can be closed.
Comment 7 Harald Eilertsen freebsd_committer freebsd_triage 2025-11-04 17:28:30 UTC
(In reply to Ryan Shaw from comment #5)
I'd be interested to know if the current openjdk25 port works for you. I will probably back port it to at least the more recent jdk versions, but it would be good to know if there's anything not working before I do that :)
Comment 8 Michael Osipov freebsd_committer freebsd_triage 2025-11-05 08:01:09 UTC
How much space does one save on disk? and the other question is whether this makes java.awt.headless property obsolete?
Comment 9 Harald Eilertsen freebsd_committer freebsd_triage 2025-11-05 11:47:13 UTC
(In reply to Michael Osipov from comment #8)
The size of the installed jdk is not significantly smaller. It's only the libawt_xawt.so not being built. But it saves you some dependencies. I haven't measured the total size difference including dependencies.

The java.awt.headless property is still there, but since the x11/xorg support is not, it's not really needed. I.e. java.awt.GraphicsEnvironment.isHeadless() will always return true.

https://docs.oracle.com/en/java/javase/25/docs/api/java.desktop/java/awt/GraphicsEnvironment.html#isHeadless()

It's worth noting that this only concerns GUI apps using awt. Other toolkits like swt that is not based on awt are still able to display as normal.

It may be possible to build a headless JRE, that will save more space on disk as long as you don't need the full jdk (javac, jdb etc.)
Comment 10 Yonas Yanfa 2025-11-05 14:31:16 UTC
(In reply to Harald Eilertsen from comment #9)

I'd like a headless JRE.
Comment 11 Michael Osipov freebsd_committer freebsd_triage 2025-11-05 14:32:55 UTC
(In reply to Yonas Yanfa from comment #10)

Me as well. I have deployments which just need a JRE, e.g. webapps on Tomcat.
Comment 12 Harald Eilertsen freebsd_committer freebsd_triage 2025-11-06 10:41:22 UTC
(In reply to Michael Osipov from comment #11)
> (In reply to Yonas Yanfa from comment #10)

Allright, I'll see if I can make that work.
Comment 13 Harald Eilertsen freebsd_committer freebsd_triage 2025-11-12 13:46:15 UTC
Patch to add `jre_headless` flavor here:
https://reviews.freebsd.org/D53707
Comment 14 commit-hook freebsd_committer freebsd_triage 2025-11-25 13:45:07 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=558ad9ce89912a8c688d03c7e2560b55d49c5541

commit 558ad9ce89912a8c688d03c7e2560b55d49c5541
Author:     Harald Eilertsen <haraldei@FreeBSD.org>
AuthorDate: 2025-11-12 13:39:14 +0000
Commit:     Harald Eilertsen <haraldei@FreeBSD.org>
CommitDate: 2025-11-25 13:44:21 +0000

    java/openjdk25: Add jre_headless flavor

    Add flavor to make a headless jre package, where dev tools and x11
    support is removed. As requested in Bug #266059.

    PR:             266059
    Reviewed by:    fuz, jrm
    Approved by:    fuz (Mentor), jrm
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D53707

 java/openjdk25/Makefile | 50 +++++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 20 deletions(-)