Java: Difference between revisions

m buildmavenpackage and fix buildmaven link
Miniluz (talk | contribs)
VSCode + Language Support for Java (TM) by Red Hat extension: Add alternate solution for using Language Support for Java
Line 24: Line 24:


== VSCode + Language Support for Java (TM) by Red Hat extension ==
== 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):<syntaxhighlight lang="nix">
Unfortunately the extension contains and uses a version of the JRE which 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):<syntaxhighlight lang="nix">
devShell = pkgs.mkShell {
devShell = pkgs.mkShell {
   buildInputs = [
   buildInputs = [
Line 38: Line 38:
};
};
</syntaxhighlight>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.  
</syntaxhighlight>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.  
Another solution is to use the <code>[https://github.com/redhat-developer/vscode-java?tab=readme-ov-file#supported-vs-code-settings java.jdt.ls.java.home]</code> VSCode setting to point to a nix-built Java 17. For example, using home-manager's settings: <syntaxhighlight lang="nix">
programs.vscode.enable = true;
programs.vscode.extensions = [ pkgs.vscode-extensions.redhat.java ];
programs.vscode.userSettings = {
  "java.jdt.ls.java.home" = "${pkgs.jdk17}";
};
</syntaxhighlight>Note that this will still result in the extension downloading its own JRE, it just will not be used.


== Using Oracle JDK instead of Open JDK ==
== Using Oracle JDK instead of Open JDK ==