question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Standalone Java files are not linked to default project unless being opened. Need to scaffold a project without Maven/Gradle

See original GitHub issue

As far as I know, currently whenever a standalone Java file is opened in VS Code, it is linked into “src” folder under the default project “jdt.ls-java-project”. So it allows users to start from scratch without importing a project.

But the feature doesn’t work for some scenarios. If I open a folder with some existing Java files, the files will not be linked to the default project unless I open each of one by one. Mentioned by @cjbailey in https://github.com/Microsoft/vscode-java-debug/issues/344#issuecomment-416157868

A simplified example:

There is a “Hello.java” file existing in my file system, and its’ content is:

/**
 * Hello
 */
public class Hello {
    public static void sayHello() {
        System.out.println("hello");
    }
}

I wanted to write simple Java code from scratch to test this Hello.java, so I created a “new folder” as my project root and a “src” folder to put java files, and copy “Hello.java” to the folder. Then I open this “new folder” with VSCode. Without opening “Hello.java” (this is important), I created a “Main.java”, referencing a method in Hello and press F5 to run, error occurred: image

Some thoughts

  • If it supports to create a project from current workspace root folder, it would be a better experience for users to start from scratch. For a well-structured folder, I think it also makes more sense to create a project for it instead of link all the Java files into an invisible default project. In Eclipse, the “Import Projects from File System” just works fine for the case, I’m not sure if it is possible to have this feature here.

  • Moreover, a potential feature (https://github.com/redhat-developer/vscode-java/issues/619) enables user to set the source folder, in case language server fails to recognize source folder correctly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
testforstephencommented, Oct 23, 2018

@michael-hawker The parent folder represents the direct folder containing the open file. Is this same as the current folder you mentioned? right?

1reaction
testforstephencommented, Oct 22, 2018

One idea is when the user opens a standalone java file, prompt the user whether to add the parent directory as Java Source Folder, this will make all standalone java files under the same directory to be added to the default project classpath. image

When the user wants to cancel the parent directory as Java Source Folder, he/she can do that through the context menu Unmark as Java Source Folder. image

In this approach, the user doesn’t need create a new eclipse project and get bothered by the generated .classpath and .project files, but directly leverage the default project to manage the standalone java files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create Java project in Netbeans, without using Maven ...
By default, the user of Apache NetBeans is now encouraged to consider Apache Maven and Apache Gradle first. The old Ant-related categories are ......
Read more >
Building applications with Maven - Quarkus
Open the project directory in VS Code. If you have installed the Java Extension Pack (grouping a set of Java extensions), the project...
Read more >
Maven Getting Started Guide
The defaults for Maven are often sufficient, but if you need to change the ... has been created for the new project, and...
Read more >
Creating Java Project Without Maven in Apache NetBeans (11 ...
In this article, you will find the steps to create a simple Java Project without Maven in Apache NetBeans (v 11 and higher)....
Read more >
The Grails Framework 2.5.6 - GitHub Pages
Grails' Scaffolding feature has been split into a separate plugin. ... Just open the project with File -> New Project -> Create project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found