-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standalone Java files are not linked to default project unless being opened. Need to scaffold a project without Maven/Gradle #620
Comments
Any thoughts? Currently there is no way to scaffold/import a simple non-Maven/non-Gradle project, all the standalone Java files (even if they are not related) are directly linked to a default project when being open. When opening a well-structured simple project, following things are strange:
|
@testforstephen why would it be the parent folder instead of the current folder? Most basic Java editors (e.g. jGrasp) will just take the current folder for the open file as the classpath. |
@michael-hawker The parent folder represents the direct folder containing the open file. Is this same as the current folder you mentioned? right? |
@testforstephen yup, think 'containing folder' is the clearer term to avoid my former confusion. :) |
@testforstephen @fbricon I suggest to use a folder based standalone file strategy, connect different java files under different folder to default project will make the default project difficult to compile (due to naming conflicts) and bring in the performance issue(in case of a lot of java files). I suggest to look into the parent folder when opening standalone java file, decided by the folder structure to import the projects under that folder or create a special project related to that folder takes the folder as the project root and source root if no projects are found. Whenever a standalone Java file is opened in vscode, we try to follow some rules to find the right folder for that file:
The logic to detect the java project system in a folder:
|
Standalone file support has been reworked. Opening a folder should now reference all java files in it, via the "invisible project" concept. |
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 microsoft/vscode-java-debug#344 (comment)
A simplified example:
There is a "Hello.java" file existing in my file system, and its' content is:
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:
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 (Need new feature: use as source folder #619) enables user to set the source folder, in case language server fails to recognize source folder correctly.
The text was updated successfully, but these errors were encountered: