DEV Community

Cover image for How to Configure Cursor with Java
Anderson Bosa
Anderson Bosa

Posted on

How to Configure Cursor with Java

Objective

Configure the Cursor IDE to work with Java projects that use a different version of Runtime. In this guide, Corretto v17.0.13 will be used. You will learn how to configure your Cursor to run and debug your Java applications and tests.

Please feel free to make suggestions and comments: https://sandwiche.me/andersonbosadev

Image

Getting started

  1. Start by installing the following extensions (you can add them to the .vscode/extensions.json file so the IDE recommends them)
{
    "recommendations": [
        // for now, not available in marketplace of Cursor IDE (only VSCODE) 🥺
        "oracle.oracle-java", 
        "vscjava.vscode-java-debug",
        "vscjava.vscode-java-pack",
        "oracle.oracle-java",
        "vscjava.vscode-maven",
        "vscjava.vscode-java-dependency",
        "vmware.vscode-boot-dev-pack"
    ]
}
Enter fullscreen mode Exit fullscreen mode

After installing these extensions, we need to disable some extensions because they cause malfunction. To do this, disable the redhat.java extension, which will also disable some others (as they depend on it), resulting in the following extensions being disabled:

redhat.java
    vscjava.vscode-java-test
    vmware.vscode-spring-boot
    vscjava.vscode-spring-boot-dashboard
Enter fullscreen mode Exit fullscreen mode

Img

2. Shenanigans

We need the oracle.oracle-java extension for everything to work, but it is not available in the Cursor IDE Marketplace (at the time of this guide). Therefore, a workaround is needed to download and install the extension in Cursor.

It's possible, but it's a bit tricky. Fortunately, I found an application that helps us, and I made it available in my repository after doing a Code Review.

Access the application below to search and download the VSIX for the oracle.oracle-java extension:

Img

Go to Cursor, Open “Command Prompt” (cmd + shift + p) and type “extensions: vsix“ to find the “Extensions: Install from VSIX” functionality.

Img

Then just select the file and install it.

Img

If everything was successful so far, the extension will appear in the extensions menu.

Img

3. Configure your Runtime ☺️

To make everything work, you just need to define where your Runtime is installed in your Cursor IDE settings.

Open “Command Prompt” (cmd + shift + p) and type “pref user json“ to find the option with the JSON of your settings and add the key jdk.jdkhome with the path of your Runtime.

"jdk.jdkhome": "/Users/anbosa/Library/Java/JavaVirtualMachines/corretto-17.0.13/Contents/Home",
Enter fullscreen mode Exit fullscreen mode

Img

To validate that everything is as expected, select a test you want to run and right-click. The following options will appear:

Img

Now you have Cursor configured to work with Java in a defined Runtime ☺️

Img

Top comments (0)