running Windows flavor of java.exe/jpackage.exe on a Docker container using Wine

What is Wine

Wine is a Windows API layer for POSIX family OSs.
To rephrase it, you can run many Windows applications on Linux/macOS without virtualizing Windows OS.

Why you may want to run Windows version of Java on Linux/macOS

Java is a “Write once, run anywhere” language and basically there is no need to run java.exe on Linux/macOS boxes. If you need to ensure your application compatibility with Windows, it’s better using virtualized environment than using Wine. But when it comes to packaging, you definitely want to run jpackage.exe on a Docker container to build application packages for Windows from Linux/macOS.

working example

Below is a working example for running jpackage.exe inside a Docker container. This docker file was carefully crafted by a non-Windows/Wine expert. Please let me know if there’s anything I can improve this.

FROM debian:bullseye

RUN dpkg --add-architecture i386
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y fakeroot
RUN apt-get install -y unzip
RUN apt-get install -y gnupg

# install JDK
RUN curl --output /opt/ \
    && cd /opt/  \
    && unzip \
    && rm 
ENV JAVA_HOME /opt/jdk-17

# install Wine
RUN curl --output winehq.key
RUN apt-key add winehq.key
RUN rm winehq.key
RUN apt-get install software-properties-common -y
RUN add-apt-repository 'deb bullseye main'
RUN apt-get update
RUN apt install --install-recommends  winehq-staging -y
RUN wine --version
RUN wine wineboot --init

# install WIX TOOLSET
RUN mkdir /opt/wix311 \
    && cd /opt/wix311  \
    && curl -L --output /opt/wix311/  \
    && unzip \
    && rm
# WIX TOOLSET is requring .NET.
RUN curl --output winetricks &&\
    chmod +x winetricks && \
    mv -v winetricks /usr/local/bin

# DONNO why dotnet48 installation fails with "warning: exit status 5 - user selected 'Cancel' "
ENV WINEPREFIX=/dotnet-test
RUN winetricks --optout -q dotnet48

ENV WINEPATH /opt/jdk-17/bin\;/opt/wix311