depot/third_party/nixpkgs/pkgs/development/compilers/openjdk/tests/hello-logging.nix
Default email 159e378cbb Project import generated by Copybara.
GitOrigin-RevId: c04d5652cfa9742b1d519688f65d1bbccea9eb7e
2024-09-19 17:19:46 +03:00

47 lines
938 B
Nix

{ 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 = ''
runHook preBuild
${jdk}/bin/javac src/Hello.java
runHook postBuild
'';
installPhase = ''
runHook preInstall
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
runHook postInstall
'';
}