Packaging maven project

Hello guys! I’m currently trying to package fillius which uses maven as its building tool. So I found this page and applied some changes to it, where I thought it would make sense to change them (like changing the package name in the installPhase) and I’ve got the following result:

{ lib
, jre
, makeWrapper
, maven
}:
let
  pname = "fillius";
in
maven.buildMavenPackage {
  inherit pname;
  version = "1.14.2";

  src = builtins.path {
    path = ../.;
  };

  mvnHash = "sha256-/upQzsx0NwcHeT4eVACsQpJKWmDGBHtMnGHd1BlqtBM=";

  # tests want to create an X11 window which isn't often feasable
  doCheck = false;

  nativeBuildInputs = [ makeWrapper ];

  installPhase = ''
    mkdir -p $out/bin $out/share/${pname}
    install -Dm644 ${pname}/target/${pname}.jar $out/share/${pname}

    makeWrapper ${jre}/bin/java $out/bin/${pname} \
      --add-flags "-jar $out/share/${pname}/${pname}.jar"
  '';

  meta = with lib; {
    description = "Filius is a network simulator for educational purpose";
    homepage = "https://gitlab.com/filius1/filius";
    license = [ licenses.gpl2 licenses.gpl3 ];
    mainProgram = "fillius";
  };
}

Now the line

install -Dm644 ${pname}/target/${pname}.jar $out/share/${pname}

in the installPhase gives me problems because if I execute nix build, I’m getting the following output:

error: builder for '/nix/store/1bgya3zx2ivrd2rzs5b77jsn57i9w9nz-fillius-1.14.2.drv' failed with exit code 1;
       last 25 log lines:
       > [INFO] Copying micrometer-commons-1.10.11.jar to /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/lib/micrometer-commons-1.10.11.jar
       > [INFO] Copying commons-cli-1.4.jar to /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/lib/commons-cli-1.4.jar
       > [INFO] Copying semantic-version-2.1.0.jar to /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/lib/semantic-version-2.1.0.jar
       > [INFO] Copying slf4j-api-1.7.30.jar to /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/lib/slf4j-api-1.7.30.jar
       > [INFO] Copying logback-classic-1.2.3.jar to /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/lib/logback-classic-1.2.3.jar
       > [INFO] Copying logback-core-1.2.3.jar to /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/lib/logback-core-1.2.3.jar
       > [INFO]
       > [INFO] --- antrun:1.7:run (default) @ filius ---
       > [INFO] Executing tasks
       >
       > main:
       >      [gzip] Building: /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/changelog.gz
       > [INFO] Executed tasks
       > [INFO]
       > [INFO] --- jar:2.4:jar (default-jar) @ filius ---
       > [INFO] Building jar: /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/filius.jar
       > [INFO] ------------------------------------------------------------------------
       > [INFO] BUILD SUCCESS
       > [INFO] ------------------------------------------------------------------------
       > [INFO] Total time:  4.423 s
       > [INFO] Finished at: 2024-06-14T09:51:37Z
       > [INFO] ------------------------------------------------------------------------
       > @nix { "action": "setPhase", "phase": "installPhase" }
       > Running phase: installPhase
       > install: cannot stat '/nix/store/dgcxm2h1yxwg8wcs15winfk3xwx4kq0x-2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/fillius.jar': No such file or directory
       For full logs, run 'nix log /nix/store/1bgya3zx2ivrd2rzs5b77jsn57i9w9nz-fillius-1.14.2.drv'.

so, if I’m understanding it correctly, I actually need the path to /build/2wn6qm7jjr12n9yyabv2mnp6hmd9ddg1-source/target/filius.jar instead of ${pname}/target/${pname}.jar.

I’ve tried to use

install -Dm644 $build/target/${pname}.jar $out/share/${pname}

because I thought $build would exist to access the build directory but it still failed.

May I ask how I can fix this?

Alright, the nixos-discord server helped me out:
By adding ls -hal ./* before the install command, I could see where the .jar file was, so the solution was simply:

install -Dm644 ./target/{pname}.jar $out/share/${pname}