Java

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/java17.zip https://download.bell-sw.com/java/17+35/bellsoft-jdk17+35-windows-amd64.zip \
    && cd /opt/  \
    && unzip java17.zip \
    && rm java17.zip 
ENV JAVA_HOME /opt/jdk-17

# install Wine
RUN curl --output winehq.key https://dl.winehq.org/wine-builds/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 https://dl.winehq.org/wine-builds/debian/ 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/wix311.zip https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip  \
    && unzip wix311.zip \
    && rm wix311.zip
    
# WIX TOOLSET is requring .NET.
RUN curl --output winetricks https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks &&\
    chmod +x winetricks && \
    mv -v winetricks /usr/local/bin

# DONNO why dotnet48 installation fails with "warning: exit status 5 - user selected 'Cancel' "
# https://forum.winehq.org/viewtopic.php?f=8&t=35724
ENV WINEPREFIX=/dotnet-test
RUN winetricks --optout -q dotnet48

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

WORKDIR /root