Skip to content

Log4J issues when building version 1.20 #8

@urb99Violetipz0dm2f2vBrown

Description

I can build 1.19.1 with JDK21, but when I try to build version 1.20, I get the following problem

ERROR StatusLogger Unable to load services for service class org.apache.logging.log4j.spi.Provider
 java.lang.NoSuchMethodException: no such method: java.util.ServiceLoader.load(Class,ClassLoader)ServiceLoader/invokeStatic
        at java.base@21.0.6/java.lang.invoke.MemberName.makeAccessException(MemberName.java:915)
        at java.base@21.0.6/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:994)
        at java.base@21.0.6/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:3750)
        at java.base@21.0.6/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:2675)
        at org.apache.logging.log4j.util.ServiceLoaderUtil.loadClassloaderServices(ServiceLoaderUtil.java:91)
        at org.apache.logging.log4j.util.ServiceLoaderUtil.loadServices(ServiceLoaderUtil.java:74)
        at org.apache.logging.log4j.util.ServiceLoaderUtil.loadServices(ServiceLoaderUtil.java:68)
        at org.apache.logging.log4j.util.ProviderUtil.<init>(ProviderUtil.java:67)
        at org.apache.logging.log4j.util.ProviderUtil.lazyInit(ProviderUtil.java:145)
        at org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:129)
        at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:90)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:55)
        at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
        at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
        at com.mojang.logging.LogUtils.getLogger(LogUtils.java:62)
        at net.minecraft.server.Main.<clinit>(SourceFile:65)
        at java.base@21.0.6/java.lang.invoke.DirectMethodHandle.ensureInitialized(DirectMethodHandle.java:288)
        at java.base@21.0.6/java.lang.invoke.DirectMethodHandle.internalMemberNameEnsureInit(DirectMethodHandle.java:336)
Caused by: java.lang.NoSuchMethodError: java.util.ServiceLoader.load(java.lang.Class, java.lang.ClassLoader)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.methodhandles.Util_java_lang_invoke_MethodHandleNatives.resolve(Target_java_lang_invoke_MethodHandleNatives.java:335)
        at java.base@21.0.6/java.lang.invoke.MethodHandleNatives.resolve(MethodHandleNatives.java:213)
        at java.base@21.0.6/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:962)
        at java.base@21.0.6/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:991)
        ... 18 more
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
ERROR ahi Failed to load properties from file: server.properties
 java.nio.file.NoSuchFileException: server.properties
        at java.base@21.0.6/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261)
        at java.base@21.0.6/java.nio.file.Files.newByteChannel(Files.java:379)
        at java.base@21.0.6/java.nio.file.Files.newByteChannel(Files.java:431)
        at java.base@21.0.6/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
        at java.base@21.0.6/java.nio.file.Files.newInputStream(Files.java:159)
        at ahi.b(SourceFile:62)
        at ahf.a(SourceFile:137)
        at ahg.<init>(SourceFile:12)
        at net.minecraft.server.Main.main(SourceFile:115)
        at java.base@21.0.6/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

I suspect it's a problem with the json configuration in the configuration folder

Github Actions :

name: Build Native Minecraft Server

on:
  push:
    branches:
      - main
    tags:
      - 'v-*'
  pull_request:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  

      # Create tag with format v-YYYY-MM-DD if not already running on a tag
      - name: Create tag if not exists
        if: "!startsWith(github.ref, 'refs/tags/')"
        run: |
          TAG_NAME="v-$(date +'%Y-%m-%d')"
          echo "Creating tag $TAG_NAME"
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git tag "$TAG_NAME" || echo "Tag already exists, skipping tag creation"
          git push origin "$TAG_NAME" || echo "Tag already exists remotely, skipping push"
          echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV

      - uses: graalvm/setup-graalvm@v1
        with:
          java-version: '21'
          github-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Check build.sh
        shell: bash
        run: shellcheck build.sh

      - name: Build and run native Minecraft server
        shell: bash
        run: |
          ./build.sh

      - name: Upload Build Artifact
        uses: actions/upload-artifact@v4
        with:
          name: minecraft-server
          path: ./native-minecraft-server

      # Extract the tag name if we're running from a tag trigger
      - name: Set tag name from ref
        if: startsWith(github.ref, 'refs/tags/')
        run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

      # Create a zip file for the release
      - name: Zip artifact for release
        run: zip -r minecraft-server.zip .
        if: env.TAG_NAME != ''

      # Create a release using the tag
      - name: Create Release
        id: create_release
        uses: softprops/action-gh-release@v1
        if: env.TAG_NAME != ''
        with:
          tag_name: ${{ env.TAG_NAME }}
          name: Release ${{ env.TAG_NAME }}
          draft: false
          prerelease: false
          files: minecraft-server.zip
          token: ${{ secrets.GITHUB_TOKEN }}

build.sh

#!/usr/bin/env bash

set -o errexit
set -o nounset

SERVER_JAR_DL="https://piston-data.mojang.com/v1/objects/8f3112a1049751cc472ec13e397eade5336ca7ae/server.jar"
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
BUILD_DIR="${SCRIPT_DIR}/build"
JAR_PATH="${BUILD_DIR}/server.jar"
META_INF_PATH="${BUILD_DIR}/META-INF"
BINARY_NAME="native-minecraft-server"
NI_EXEC="${GRAALVM_HOME:-}/bin/native-image"
readonly SERVER_JAR_DL SCRIPT_DIR BUILD_DIR JAR_PATH META_INF_PATH BINARY_NAME NI_EXEC

if [[ -z "${GRAALVM_HOME:-}" ]]; then
    echo "\$GRAALVM_HOME is not set. Please provide a GraalVM installation. Exiting..."
    exit 1
fi

if ! command -v "${NI_EXEC}" &> /dev/null; then
    echo "Installing GraalVM Native Image..."
    "${GRAALVM_HOME}/bin/gu" install --no-progress native-image
fi

if [[ ! -d "${BUILD_DIR}" ]]; then
    mkdir "${BUILD_DIR}"
fi
pushd "${BUILD_DIR}" > /dev/null

if [[ ! -f "${JAR_PATH}" ]]; then
    echo "Downloading Minecraft's server.jar..."
    curl --show-error --fail --location -o "${JAR_PATH}" "${SERVER_JAR_DL}"
fi

if [[ ! -d "${META_INF_PATH}" ]]; then
    echo "Extracting resources from Minecraft's server.jar..."
    unzip -qq "${JAR_PATH}" "META-INF/*" -d "."
fi

if [[ ! -f "${META_INF_PATH}/classpath-joined" ]]; then
    echo "Unable to determine classpath. Exiting..."
    exit 1
fi
CLASSPATH_JOINED=$(cat "${META_INF_PATH}/classpath-joined")
readonly CLASSPATH_JOINED

if [[ ! -f "${META_INF_PATH}/main-class" ]]; then
    echo "Unable to determine main class. Exiting..."
    exit 1
fi
MAIN_CLASS=$(cat "${META_INF_PATH}/main-class")
readonly MAIN_CLASS

pushd "${META_INF_PATH}" > /dev/null
"${NI_EXEC}" --no-fallback \
  -H:ConfigurationFileDirectories="${SCRIPT_DIR}/configuration/" \
  --enable-url-protocols=https \
  --initialize-at-run-time=io.netty,org.apache.logging.log4j \
  -H:+AllowVMInspection \
  --initialize-at-build-time=net.minecraft.util.profiling.jfr.event \
  -H:Name="${BINARY_NAME}" \
  -cp "${CLASSPATH_JOINED//;/:}" \
  "${MAIN_CLASS}"

mv "${BINARY_NAME}" "${SCRIPT_DIR}/${BINARY_NAME}"
popd > /dev/null # Exit $META_INF_PATH
popd > /dev/null # Exit $BUILD_DIR

if command -v upx &> /dev/null; then
    echo "Compressing the native Minecraft server with upx..."
    upx "${SCRIPT_DIR}/${BINARY_NAME}"
fi

echo ""
echo "Done! The native Minecraft server is located at:"
echo "${SCRIPT_DIR}/${BINARY_NAME}"

Also why can't it build on Windows?
The following problems occurred when building 1.18.2 using jdk17 22.0.2 in this project

[22:05:21] [main/INFO]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD'
[22:05:21] [main/WARN]: Assets URL 'resource:/assets/.mcassetsroot' uses unexpected schema
[22:05:21] [main/WARN]: Assets URL 'resource:/data/.mcassetsroot' uses unexpected schema
Exception in thread "main" [22:05:21] [main/INFO]: [STDERR]: java.lang.UnsatisfiedLinkError: jdk.jfr.internal.JVM.isExcluded(Ljava/lang/Class;)Z [symbol: Java_jdk_jfr_internal_JVM_isExcluded or Java_jdk_jfr_internal_JVM_isExcluded__Ljava_lang_Class_2]
[22:05:21] [main/INFO]: [STDERR]:       at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:152)
[22:05:21] [main/INFO]: [STDERR]:       at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:54)
[22:05:21] [main/INFO]: [STDERR]:       at jdk.jfr@21.0.6/jdk.jfr.internal.JVM.isExcluded(Native Method)
[22:05:21] [main/INFO]: [STDERR]:       at jdk.jfr@21.0.6/jdk.jfr.internal.MetadataRepository.register(MetadataRepository.java:137)
[22:05:21] [main/INFO]: [STDERR]:       at jdk.jfr@21.0.6/jdk.jfr.internal.MetadataRepository.register(MetadataRepository.java:132)
[22:05:21] [main/INFO]: [STDERR]:       at jdk.jfr@21.0.6/jdk.jfr.FlightRecorder.register(FlightRecorder.java:128)
[22:05:21] [main/INFO]: [STDERR]:       at java.base@21.0.6/java.lang.Iterable.forEach(Iterable.java:75)
[22:05:21] [main/INFO]: [STDERR]:       at atd.<init>(SourceFile:75)
[22:05:21] [main/INFO]: [STDERR]:       at atd.<clinit>(SourceFile:65)
[22:05:21] [main/INFO]: [STDERR]:       at ate.<clinit>(SourceFile:18)
[22:05:21] [main/INFO]: [STDERR]:       at dn.<init>(SourceFile:211)
[22:05:21] [main/INFO]: [STDERR]:       at zc.<init>(SourceFile:43)
[22:05:21] [main/INFO]: [STDERR]:       at zc.a(SourceFile:80)
[22:05:21] [main/INFO]: [STDERR]:       at zk.a(SourceFile:44)
[22:05:21] [main/INFO]: [STDERR]:       at net.minecraft.server.Main.main(SourceFile:155)
[22:05:21] [main/INFO]: [STDERR]:       at java.base@21.0.6/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions