I have some projects that require JDK 14 and that I’d like to develop in Eclipse.
I’ve created a shell.nix
file with this content:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
eclipses.eclipse-java
jdk14
# keep this line if you use bash
bashInteractive
];
}
This makes JDK14 available:
nix-shell --command "which java"
# /nix/store/swbd0b2gprpid3ksa5wgw0ablmqr2bkk-openjdk-14.0.2-ga/bin/java
nix-shell --command "which javac"
# /nix/store/swbd0b2gprpid3ksa5wgw0ablmqr2bkk-openjdk-14.0.2-ga/bin/javac
nix-shell --command "echo $JAVA_HOME"
# /nix/store/swbd0b2gprpid3ksa5wgw0ablmqr2bkk-openjdk-14.0.2-ga/lib/openjdk
But Eclipse in that shell doesn’t know about it. Each time I create a new workspace, I have to
- go to menu Window > Preferences
- in the Preferences, open Java > Installed JREs
- there
- optionally delete the pre-configure JDK 11 (
/nix/store/352y6g6f8x3hvm68ddhwk2qffaig14l2-openjdk-11.0.9+11/lib/openjdk
) - add a “Standard VM” with
/nix/store/swbd0b2gprpid3ksa5wgw0ablmqr2bkk-openjdk-14.0.2-ga/lib/openjdk
- optionally delete the pre-configure JDK 11 (
- in the Preferences, open Java > Installed JREs > Execution Environments
- there
- set the newly added VM for at least JavaSE-14
- optionally set it also for the other predefined execution environments
Is there a way to avoid this manual setup?
Inspired by
I tried with
{ pkgs ? import <nixpkgs> {
overlays = [ (self: super: {
jdk = super.jdk14;
}) ];
} }:
pkgs.mkShell {
buildInputs = with pkgs; [
eclipses.eclipse-java
jdk
# keep this line if you use bash
bashInteractive
];
}
and
{ pkgs ? import <nixpkgs> {} }:
let
pkgs = import <nixpkgs> { overlays = [ (self: super: {
jdk = super.adoptopenjdk-jre-openj9-bin-11;
}) ]; };
in
pkgs.mkShell {
buildInputs = with pkgs; [
eclipses.eclipse-java
jdk
# keep this line if you use bash
bashInteractive
];
}
But neither seems to change which JDK is pre-configured in Eclipse, nor what the environment set in its wrapper script is:
nix-shell --command "cat $(which eclipse)"
#! /nix/store/516z50fm1jbpcl32qnzy7kynrh0vl22w-bash-4.4-p23/bin/bash -e
export PATH='/nix/store/352y6g6f8x3hvm68ddhwk2qffaig14l2-openjdk-11.0.9+11/bin'${PATH:+':'}$PATH
export LD_LIBRARY_PATH='/nix/store/0ds5gvys9awz8ab2mybyfhy7532yrhxa-glib-2.66.2/lib:/nix/store/lbaq8v4r1vzbadw02j0adfhin00pyyc8-gtk+3-3.24.23/lib:/nix/store/izrgpwzy91jg9mpqprs14v7vycqq39z8-libXtst-1.2.3/lib:/nix/store/krn2r4jnhdw5a2ppz2zhfmra63kd9wkz-webkitgtk-2.30.3/lib'${LD_LIBRARY_PATH:+':'}$LD_LIBRARY_PATH
export XDG_DATA_DIRS='/nix/store/rhyybrmwif0jkzbdx6fxszxinfl8qpl5-gsettings-desktop-schemas-3.38.0/share/gsettings-schemas/gsettings-desktop-schemas-3.38.0:/nix/store/lbaq8v4r1vzbadw02j0adfhin00pyyc8-gtk+3-3.24.23/share/gsettings-schemas/gtk+3-3.24.23'${XDG_DATA_DIRS:+':'}$XDG_DATA_DIRS
exec "/nix/store/n31ln3p9p6rfpdpg4qask5ngb9p623xj-eclipse-java-4.17/eclipse/eclipse" -configuration $HOME/.eclipse/org.eclipse.platform_4.17.0/configuration "$@"
(I don’t really care what JDK / JRE is used to run eclipse, as long as it works. I just want different defaults for freshly created Eclipse workspaces.)