Skip to content

Support for .jar files in tasks and debugger #220

@lukejans

Description

@lukejans

I’m not sure how the maintainers would like to implement this, but it would be great to have support for .jar files without any configuration or at least some mention of it in the documentation for this extension. Below is an example of the Zed settings files I’ve created to make jar files work in my project. I haven’t done much research on this, but I just wanted to get the conversation started. I’m also not sure if using a lib/ folder is better, but here’s the current project structure:

./
├── .zed/
│   ├── debug.json
│   ├── settings.json
│   └── tasks.json
├── MyJar.jar
├── bin/
└── src/
    ├── Main.java
    └── ExampleFile.java
// .zed/debug.json
[
    {
        "label": "Debug $ZED_STEM",
        "adapter": "Java",
        "request": "launch",
        "mainClass": "$ZED_STEM",
        "build": {
            "command": "javac -cp $ZED_WORKTREE_ROOT/MyJar.jar -d $ZED_WORKTREE_ROOT/bin $ZED_WORKTREE_ROOT/src/*.java",
            "shell": {
                "with_arguments": {
                    "program": "/bin/sh",
                    "args": ["-c"],
                },
            },
        },
    },
]
// .zed/settings.json
{
    "lsp": {
        "jdtls": {
            "initialization_options": {
                "project": {
                    "sourcePaths": ["src"],
                },
                "settings": {
                    "java": {
                        "project": {
                            "referencedLibraries": ["MyJar.jar"],
                        },
                    },
                },
            },
        },
    },
}
// .zed/tasks.json
[
    {
        "label": "Run Main with jar",
        "command": "find . -name '*.java' -not -path './bin/*' -print0 | xargs -0 javac -cp MyJar.jar -d bin && java -cp 'bin:MyJar.jar' Main",
        "use_new_terminal": false,
        "reveal": "always",
        "shell": {
            "with_arguments": {
                "program": "/bin/sh",
                "args": ["-c"],
            },
        },
    },
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions