diff --git a/SOURCES/0001-Adapt-build.patch b/SOURCES/0001-Adapt-build.patch
index 36ad5d1..1eb44d8 100644
--- a/SOURCES/0001-Adapt-build.patch
+++ b/SOURCES/0001-Adapt-build.patch
@@ -1,7 +1,7 @@
-From 52ef407584801916d6e60c4f4c5411023b5ac369 Mon Sep 17 00:00:00 2001
+From 2560a89cc5537890c3a692263715c93b97d7ea37 Mon Sep 17 00:00:00 2001
 From: Michael Simacek <msimacek@redhat.com>
 Date: Mon, 16 Jan 2017 11:29:06 +0100
-Subject: [PATCH 1/6] Adapt build
+Subject: [PATCH 1/7] Adapt build
 
 ---
  native/Makefile | 3 +--
@@ -29,5 +29,5 @@ index 1bea2dc..cb3afed 100644
  $(TESTLIB): $(BUILD)/testlib.o
  	$(LD) $(LDFLAGS) $< $(LIBS)
 -- 
-2.20.1
+2.38.1
 
diff --git a/SOURCES/0002-Load-system-library.patch b/SOURCES/0002-Load-system-library.patch
index b8785b0..ed5d21d 100644
--- a/SOURCES/0002-Load-system-library.patch
+++ b/SOURCES/0002-Load-system-library.patch
@@ -1,14 +1,14 @@
-From 3d08314de0494ff8bdc1a7bccc0ecc1730dbdd60 Mon Sep 17 00:00:00 2001
+From 28f5c64f5443a6d465663a1b737e9fc20b7364d4 Mon Sep 17 00:00:00 2001
 From: Michael Simacek <msimacek@redhat.com>
 Date: Mon, 16 Jan 2017 11:31:32 +0100
-Subject: [PATCH 2/6] Load system library
+Subject: [PATCH 2/7] Load system library
 
 ---
  src/com/sun/jna/Native.java | 80 ++-----------------------------------
  1 file changed, 4 insertions(+), 76 deletions(-)
 
 diff --git a/src/com/sun/jna/Native.java b/src/com/sun/jna/Native.java
-index eae060f..11bcc5b 100644
+index 0cf39fa..603659c 100644
 --- a/src/com/sun/jna/Native.java
 +++ b/src/com/sun/jna/Native.java
 @@ -912,84 +912,12 @@ public final class Native implements Version {
@@ -101,5 +101,5 @@ index eae060f..11bcc5b 100644
  
      static final String JNA_TMPLIB_PREFIX = "jna";
 -- 
-2.20.1
+2.38.1
 
diff --git a/SOURCES/0003-Tests-headless.patch b/SOURCES/0003-Tests-headless.patch
index 9a4645d..a53eaa8 100644
--- a/SOURCES/0003-Tests-headless.patch
+++ b/SOURCES/0003-Tests-headless.patch
@@ -1,17 +1,17 @@
-From c0f33e9ed0a5cfd79b58487c2a36c9b880b49947 Mon Sep 17 00:00:00 2001
+From 4b05abecb7b8a1edc0a32048ab12aba6ee1d6824 Mon Sep 17 00:00:00 2001
 From: Michael Simacek <msimacek@redhat.com>
 Date: Mon, 16 Jan 2017 11:32:32 +0100
-Subject: [PATCH 3/6] Tests headless
+Subject: [PATCH 3/7] Tests headless
 
 ---
  build.xml | 1 +
  1 file changed, 1 insertion(+)
 
 diff --git a/build.xml b/build.xml
-index d5c2bbc..835c02b 100644
+index 0153731..8dbe173 100644
 --- a/build.xml
 +++ b/build.xml
-@@ -1202,6 +1202,7 @@ cd ..
+@@ -1250,6 +1250,7 @@ cd ..
        <sysproperty key="jna.nosys" value="true"/>
        <sysproperty key="jna.builddir" file="${build}"/>
        <sysproperty key="jna.nativedir" file="${build.native}"/>
@@ -20,5 +20,5 @@ index d5c2bbc..835c02b 100644
        <formatter type="brief" usefile="false"/>
        <formatter type="xml"/>
 -- 
-2.20.1
+2.38.1
 
diff --git a/SOURCES/0004-Fix-javadoc-build.patch b/SOURCES/0004-Fix-javadoc-build.patch
index dc5ab54..c5860ba 100644
--- a/SOURCES/0004-Fix-javadoc-build.patch
+++ b/SOURCES/0004-Fix-javadoc-build.patch
@@ -1,17 +1,17 @@
-From ced8baacd3bccba7ebaba80785b891bf579af215 Mon Sep 17 00:00:00 2001
+From 042a878f130a855faae8706abc12a4c417607753 Mon Sep 17 00:00:00 2001
 From: Michael Simacek <msimacek@redhat.com>
 Date: Tue, 31 Jan 2017 14:21:19 +0100
-Subject: [PATCH 4/6] Fix javadoc build
+Subject: [PATCH 4/7] Fix javadoc build
 
 ---
  build.xml | 1 +
  1 file changed, 1 insertion(+)
 
 diff --git a/build.xml b/build.xml
-index 835c02b..cecafd0 100644
+index 8dbe173..741ab6e 100644
 --- a/build.xml
 +++ b/build.xml
-@@ -1307,6 +1307,7 @@ cd ..
+@@ -1355,6 +1355,7 @@ cd ..
        <group title="Platform Specific" packages="com.sun.jna.platform.*"/>
  
        <arg value="-notimestamp"/>
@@ -20,5 +20,5 @@ index 835c02b..cecafd0 100644
      <jar jarfile="${platform-javadoc-jar}" createUnicodeExtraFields="never" encoding="UTF-8">
        <fileset dir="${javadoc}" />
 -- 
-2.20.1
+2.38.1
 
diff --git a/SOURCES/0005-Fix-duplicate-manifest-entry.patch b/SOURCES/0005-Fix-duplicate-manifest-entry.patch
index 01ea16c..f90fb2f 100644
--- a/SOURCES/0005-Fix-duplicate-manifest-entry.patch
+++ b/SOURCES/0005-Fix-duplicate-manifest-entry.patch
@@ -1,17 +1,17 @@
-From de939d7c9266f89542cea5ebef5980a95f1244a9 Mon Sep 17 00:00:00 2001
+From c86b3417e9588cdbb43d7034e16a22d4b815ce95 Mon Sep 17 00:00:00 2001
 From: Mikolaj Izdebski <mizdebsk@redhat.com>
 Date: Mon, 10 Jul 2017 11:48:43 +0200
-Subject: [PATCH 5/6] Fix duplicate manifest entry
+Subject: [PATCH 5/7] Fix duplicate manifest entry
 
 ---
  build.xml | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
 
 diff --git a/build.xml b/build.xml
-index cecafd0..ad5794e 100644
+index 741ab6e..54e569c 100644
 --- a/build.xml
 +++ b/build.xml
-@@ -586,9 +586,9 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
+@@ -611,9 +611,9 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
                    includes="LICENSE,LGPL2.1,AL2.0"
                    prefix="META-INF"/>
      </jar>
@@ -24,5 +24,5 @@ index cecafd0..ad5794e 100644
  
    <target name="aar" depends="jar" description="Build Android Archive">
 -- 
-2.20.1
+2.38.1
 
diff --git a/SOURCES/0006-Remove-Werror.patch b/SOURCES/0006-Remove-Werror.patch
index 951e600..b2519f2 100644
--- a/SOURCES/0006-Remove-Werror.patch
+++ b/SOURCES/0006-Remove-Werror.patch
@@ -1,7 +1,7 @@
-From 6e8784db2fa3b3b2efedaae75d15d5d5cf3ed50c Mon Sep 17 00:00:00 2001
+From 2e21a725ac8836f51f8b9a0171d5610eea81559f Mon Sep 17 00:00:00 2001
 From: Michael Simacek <msimacek@redhat.com>
 Date: Thu, 22 Feb 2018 16:17:15 +0100
-Subject: [PATCH 6/6] Remove -Werror
+Subject: [PATCH 6/7] Remove -Werror
 
 ---
  native/Makefile | 4 ++--
@@ -26,5 +26,5 @@ index cb3afed..028c201 100644
  
  # Enable 64-bit builds if the arch demands it
 -- 
-2.20.1
+2.38.1
 
diff --git a/SOURCES/0007-Set-explicit-compiler-release.patch b/SOURCES/0007-Set-explicit-compiler-release.patch
new file mode 100644
index 0000000..769b725
--- /dev/null
+++ b/SOURCES/0007-Set-explicit-compiler-release.patch
@@ -0,0 +1,59 @@
+From a925b1196599f48bfbd85e7f37cfc7c1e9583a3f Mon Sep 17 00:00:00 2001
+From: Mikolaj Izdebski <mizdebsk@redhat.com>
+Date: Mon, 23 Jan 2023 14:53:34 +0100
+Subject: [PATCH 7/7] Set explicit compiler release
+
+---
+ build.xml | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/build.xml b/build.xml
+index 54e569c..f724bb0 100644
+--- a/build.xml
++++ b/build.xml
+@@ -101,9 +101,7 @@
+     JDK 11 is the last JDK, that supports creation of Java 6 compatible class
+     files.
+   -->
+-  <condition property="compatibility" value="1.6" else="9">
+-    <matches pattern="^1\.\d+$" string="${ant.java.version}"/>
+-  </condition>
++  <property name="compatibility" value="8"/>
+ 
+   <condition property="compatibility-check" value="true">
+     <equals arg1="${compatibility}" arg2="1.6" />
+@@ -394,6 +392,7 @@
+ 
+     <javac source="${compatibility}"
+            target="${compatibility}"
++           release="${compatibility}"
+            destdir="${classes}"
+            includeantruntime="false"
+            deprecation="on"
+@@ -405,6 +404,7 @@
+     <javac classpath="${compatibility}"
+            source="${compatibility}"
+            target="${compatibility}"
++           release="${compatibility}"
+            destdir="${classes}"
+            includeantruntime="false"
+            deprecation="on" 
+@@ -1071,6 +1071,7 @@ cd ..
+     <javac classpathref="compile-test.path"
+            source="${test.compatibility}"
+            target="${test.compatibility}"
++           release="${test.compatibility}"
+            destdir="${test.classes}"
+            includeantruntime="false"
+            includes="**/StructureFieldOrderInspector.java"
+@@ -1087,6 +1088,7 @@ cd ..
+     <javac classpathref="compile-test.path"
+            source="${test.compatibility}"
+            target="${test.compatibility}"
++           release="${test.compatibility}"
+            destdir="${test.classes}"
+            includeantruntime="false"
+            excludes="${tests.exclude-patterns}"
+-- 
+2.38.1
+
diff --git a/SPECS/jna.spec b/SPECS/jna.spec
index 6dff659..1e20e04 100644
--- a/SPECS/jna.spec
+++ b/SPECS/jna.spec
@@ -1,6 +1,6 @@
 Name:           jna
 Version:        5.6.0
-Release:        6%{?dist}
+Release:        8%{?dist}
 Summary:        Pure Java access to native libraries
 # Most of code is dual-licensed under either LGPL 2.1+ only or Apache
 # License 2.0.  WeakIdentityHashMap.java was taken from Apache CXF,
@@ -29,6 +29,9 @@ Patch3:         0004-Fix-javadoc-build.patch
 Patch4:         0005-Fix-duplicate-manifest-entry.patch
 # We don't want newly added warnings to break our build
 Patch5:         0006-Remove-Werror.patch
+# Fix compatibility with Java 8
+# See https://bugzilla.redhat.com/show_bug.cgi?id=2162040
+Patch6:         0007-Set-explicit-compiler-release.patch
 
 # We manually require libffi because find-requires doesn't work
 # inside jars.
@@ -77,6 +80,7 @@ cp %{SOURCE1} .
 %patch3 -p1
 %patch4 -p1
 %patch5 -p1
+%patch6 -p1
 
 chmod -Rf a+rX,u+w,g-w,o-w .
 sed -i 's|@LIBDIR@|%{_libdir}/%{name}|' src/com/sun/jna/Native.java
@@ -99,7 +103,7 @@ cp lib/native/aix-ppc64.jar lib/clover.jar
 # upstream doesn't want to default to dynamic linking.
 # -Drelease removes the .SNAPSHOT suffix from maven artifact names
 #ant -Dcflags_extra.native="%{optflags}" -Ddynlink.native=true native compile javadoc jar contrib-jars
-ant -Drelease -Dcompatibility=1.6 -Dplatform.compatibility=1.6\
+ant -Drelease -Dcompatibility=1.8 -Dplatform.compatibility=1.8\
  -Dcflags_extra.native="%{optflags}" -Ddynlink.native=true -DCC=%{__cc} native dist
 # remove compiled contribs
 find contrib -name build -exec rm -rf {} \; || :
@@ -135,6 +139,14 @@ install -m 755 build/native*/libjnidispatch*.so %{buildroot}%{_libdir}/%{name}/
 
 
 %changelog
+* Mon Jan 30 2023 Zuzana Miklankova <zmiklank@redhat.com> - 5.6.0-8
+- Set correct compat. value also to ant parameters
+- Resolves: rhbz#2162040
+
+* Mon Jan 23 2023 Mikolaj Izdebski <mizdebsk@redhat.com> - 5.6.0-7
+- Fix compatibility with Java 8
+- Resolves: rhbz#2162040
+
 * Wed Aug 18 2021 Carlos O'Donell <codonell@redhat.com> - 5.6.0-6
 - Rebuilt for libffi 3.4.2 SONAME transition.
   Related: rhbz#1891914