Vscode-java: File `.classpath` cannot be re-generated automatically.

Created on 12 Jun 2018  路  6Comments  路  Source: redhat-developer/vscode-java

The scenario is:
I open a maven project, and it builds the project for me, and it works well. After wrongly deleting the .classpath file, I can never get it back. Restarting VSCode doesn't work either.

Environment
  • Operating System: Win 10 Enterprise
  • JDK version: Oracle JDK 1.8.0_171
  • Visual Studio Code version:
Version 1.24.0
Commit 6a6e02cef0f2122ee1469765b704faf5d0e0d859
Date 2018-06-06T17:35:40.560Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64
  • Java extension version: 0.26.0
Steps To Reproduce
  1. Open a maven project, e.g. a spring-boot project.
  2. Open a *.java file to activate the extension, it starts building the project.
  3. After that, .classpath and .project are auto generated.
  4. Remove files .classpath and .project.
  5. Reload window, .project has been re-generated, but .classpath cannot be re-generated.
Current Result

Missing .classpath file, the project fails to build.

Expected Result

File .classpath can be re-generated just as we first open the project.

Additional Informations

The original issue is https://github.com/Microsoft/vscode-maven/issues/64
I can easily reproduced it and made a GIF, FYI:
sample

bug prioritP2

Most helpful comment

@fbricon ok, I can have a try.

All 6 comments

@Eskibear do you want to contribute a fix to jdt.ls?

@fbricon ok, I can have a try.

Investigation

For a maven project which has been opened before, it enters branch (1), thus the project is not added into toImport.
So even the .classpath is deleted, the project won't be re-imported, so the .classpath will not be re-generated.

for (MavenProjectInfo projectInfo : files) {
    File pom = projectInfo.getPomFile();
    IContainer container = root.getContainerForLocation(new Path(pom.getAbsolutePath()));
    if (container == null) {
        digestStore.updateDigest(pom.toPath());
        toImport.add(projectInfo);
    } else {
        IProject project = container.getProject();
        if (ProjectUtils.isMavenProject(project)) {
            projects.add(container.getProject());    <----------(1)
        } else if (project != null) {
            //Project doesn't have the Maven nature, so we (re)import it
            digestStore.updateDigest(pom.toPath());
            // need to delete project due to m2e failing to create if linked and not the same name
            project.delete(IProject.FORCE | IProject.NEVER_DELETE_PROJECT_CONTENT, subMonitor.split(5));
            toImport.add(projectInfo);
        }
    }
}
if (!toImport.isEmpty()) {
    ProjectImportConfiguration importConfig = new ProjectImportConfiguration();
    configurationManager.importProjects(toImport, importConfig, subMonitor.split(75));
}

Ref: https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporter.java#L119

Question

  1. Should we re-import all maven projects during initializing language server? It ensures a successful compilation, but decrease the performance for most time.
  2. Is there any way to detect whether there's a valid .classpath, so that we might be able to re-import the project when .classpath is missing.

@fbricon

I have the same problem when i want to create a simple java project without build tools.

@CodingLegend27 If you're using the command "Java: Create Java Project" -> "No build tool" to create a simple Java project, then you don't need an explicit .classpath file. You can add extra libraries via user setting java.project.referencedLibraries.

I had some issues with debugging the java project.
So i thought first that it was an error due to the missing .classpath file.
But in the end i figured out that it was the vs code extension 'Java Language Support' by George Fraser, which always said that 'java.awt.*' cannot be imported.

TLDR: I uninstalled this extension and everything worked well again.
So no error due to missing .classpath file!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ronniehicks picture ronniehicks  路  3Comments

protoEvangelion picture protoEvangelion  路  3Comments

larixer picture larixer  路  3Comments

bilymed picture bilymed  路  3Comments

gorkem picture gorkem  路  4Comments