diff --git a/imagej-nosourcetarget.patch b/imagej-nosourcetarget.patch
new file mode 100644
index 0000000..bf6ed84
--- /dev/null
+++ b/imagej-nosourcetarget.patch
@@ -0,0 +1,11 @@
+--- source/build.xml 2022-04-08 15:40:02.598001218 +0200
++++ source/build.xml 2022-04-08 15:43:15.611177038 +0200
+@@ -6,7 +6,7 @@
+
+
+
+-
++
+
+
+
diff --git a/imagej.changes b/imagej.changes
index d9bafdd..aef634f 100644
--- a/imagej.changes
+++ b/imagej.changes
@@ -1,3 +1,13 @@
+-------------------------------------------------------------------
+Fri Apr 8 13:44:13 UTC 2022 - Fridrich Strba
+
+- Build with java source and target levels 8
+ * Fixes build in Factory with jdk17
+- Added patch:
+ * imagej-nosourcetarget.patch
+ + Do not hardcode source and target levels, but allow them to
+ be specified on ant's command-line
+
-------------------------------------------------------------------
Wed Dec 2 18:37:15 UTC 2020 - andy great
diff --git a/imagej.spec b/imagej.spec
index 874a014..486148d 100644
--- a/imagej.spec
+++ b/imagej.spec
@@ -28,12 +28,13 @@ Url: http://rsbweb.nih.gov/ij/
Source: http://rsbweb.nih.gov/ij/download/src/ij%{SrcVersion}-src.zip
Source1: %{name}.in
Source2: %{name}.desktop
+Patch0: imagej-nosourcetarget.patch
BuildRequires: ImageMagick
BuildRequires: ant
-BuildRequires: java-devel
+BuildRequires: java-devel >= 1.8
BuildRequires: unzip
BuildRequires: update-desktop-files
-Requires: java >= 1.6.0
+Requires: java >= 1.8
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
@@ -60,9 +61,10 @@ compiler.
%prep
%setup -n source
+%patch0 -p1
%build
-%ant build
+%ant -Dant.build.javac.source=1.8 -Dant.build.javac.target=1.8 build
%install
install -d -m 755 %{buildroot}%{_datadir}/%{name}