Java: Difference between revisions
SnowSquire (talk | contribs) updated package names and versions |
m Many people are struggling online to get started with Java on Nix using VSCode. This edit helps them get started quickly with VSCode. |
||
Line 22: | Line 22: | ||
* JetBrains JDK (<code>jetbrains.jdk</code>), a fork of OpenJDK with modifications made by JetBrains | * JetBrains JDK (<code>jetbrains.jdk</code>), a fork of OpenJDK with modifications made by JetBrains | ||
* Oracle's JDK (<code>oraclejdk</code>), only version 8 is available. | * Oracle's JDK (<code>oraclejdk</code>), only version 8 is available. | ||
== VSCode + Language Support for Java (TM) by Red Hat extension == | |||
Unfortunately the extension makes use of dynamically loaded libraries which nix cannot accomodate out-of-the-box. Fortunately there's a simple solution in the use of [https://github.com/Mic92/nix-ld nix-ld]. Here's a simple flake.nix to get you started (I'll focus on the devShell part for brevity): | |||
``` | |||
devShell = pkgs.mkShell { | |||
buildInputs = [ | |||
pkgs.gradle | |||
pkgs.jdk17 | |||
]; | |||
NIX_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ | |||
pkgs.stdenv.cc.cc | |||
pkgs.openssl | |||
]; | |||
NIX_LD = pkgs.lib.fileContents "${pkgs.stdenv.cc}/nix-support/dynamic-linker"; # this needs .direnv:use flake --impure | |||
}; | |||
``` | |||
The important lines are the two lines starting with "NIX_LD...". They will let nix-ld wrap the required, dynamically loaded libraries so that they are found when building the devShell. | |||
== Using Oracle JDK instead of Open JDK == | == Using Oracle JDK instead of Open JDK == |