Create Java Project on Project IDX

Hello !
Yesterday I tried to create a Java project on the IDX project, but I encountered a problem which was that no Java jdk was selected. I tried to install eclipse or even the red hat one that google recommended but nothing worked.
I hope you can help me,

Hi Natt,

To have the jdk installed you need to add it to your .idx/dev.nix file.

Here’s an example to get you started. It’s intended for Spring Boot applications but can work for other java projects as well. Feel free to remove any Spring specific details it you are not using Spring Boot.
Place this file at .idx/dev.nix, and click “Rebuild environment” when prompted:

# To learn more about how to use Nix to configure your environment
# see: https://developers.google.com/idx/guides/customize-idx-env
{ pkgs, ... }: {
  # Which nixpkgs channel to use.
  channel = "stable-23.11"; # or "unstable"
  # Use https://search.nixos.org/packages to find packages
  packages = [
    pkgs.jdk19
  ];
  # Sets environment variables in the workspace
  env = {};
  idx = {
    # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
    extensions = [
      # "vscodevim.vim"
      "redhat.java"
      "vscjava.vscode-java-debug"
      "vscjava.vscode-java-dependency"
      "vscjava.vscode-java-pack"
      "vscjava.vscode-java-test"
      "vscjava.vscode-maven"
      "Pivotal.vscode-boot-dev-pack"
      "vmware.vscode-spring-boot"
      "vscjava.vscode-spring-boot-dashboard"
      "vscjava.vscode-spring-initializr"
    ];
    # Enable previews
    previews = {
      enable = true;
      previews = {
        web = {
          # Example: run "npm run dev" with PORT set to IDX's defined port for previews,
          # and show it in IDX's web preview panel
          command = ["./gradlew" ":bootRun" "--args='--server.port=$PORT'"];
          manager = "web";
        };
      };
    };
    # Workspace lifecycle hooks
    workspace = {
      # Runs when a workspace is first created
      onCreate = {
        # Example: install JS dependencies from NPM
        # npm-install = 'npm install';
      };
      onStart = {
        # Example: start a background task to watch and re-build backend code
        # watch-backend = "npm run watch-backend";
      };
    };
  };
}

4 Likes

Can they make this more plug and play, to run Eclipse? It’s the most popular open source IDE out there.

That is an interesting idea! Can you please suggest it in our feature requests portal at https://idx.uservoice.com ?

Thanks,
Kirupa :slight_smile:

where should i found dev.nix in my flutter project

If you create workspace from IDX templates, the dev.nix files location inside .idx folder. If you import from GitHub, you must create inside .idx folder.