2021-05-03 20:48:10 +00:00
|
|
|
{ jdk
|
|
|
|
, jre
|
|
|
|
, pkgs
|
|
|
|
}:
|
|
|
|
|
|
|
|
/* 'Hello world' Java application derivation for use in tests */
|
|
|
|
let
|
|
|
|
source = pkgs.writeTextDir "src/Hello.java" ''
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
|
|
|
class Hello {
|
|
|
|
static Logger logger = Logger.getLogger(Hello.class.getName());
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
logger.log(Level.INFO, "Hello, world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
pname = "hello";
|
|
|
|
version = "1.0.0";
|
|
|
|
|
|
|
|
src = source;
|
|
|
|
|
|
|
|
buildPhase = ''
|
2024-09-19 14:19:46 +00:00
|
|
|
runHook preBuild
|
2021-05-03 20:48:10 +00:00
|
|
|
${jdk}/bin/javac src/Hello.java
|
2024-09-19 14:19:46 +00:00
|
|
|
runHook postBuild
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
installPhase = ''
|
2024-09-19 14:19:46 +00:00
|
|
|
runHook preInstall
|
2021-05-03 20:48:10 +00:00
|
|
|
|
|
|
|
mkdir -p $out/lib
|
|
|
|
cp src/Hello.class $out/lib
|
|
|
|
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cat >$out/bin/hello <<EOF;
|
|
|
|
#!/usr/bin/env sh
|
|
|
|
${jre}/bin/java -cp $out/lib Hello
|
|
|
|
EOF
|
|
|
|
chmod a+x $out/bin/hello
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
runHook postInstall
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
}
|