eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

.project doesn't update for single file after renaming the directory

Open andxu opened this issue 6 years ago • 5 comments

From @yhtsao on February 28, 2018 7:13

  • VSCode Version: 1.20.1
  • OS Version: MacOS 10.12.6
  • Language: Java
  • Extensions: Debugger for Java 0.6.0 Java Extension Pack 0.3.0 Java Test Runner 0.3.0 Language Support for Java(TM) by Red Hat 0.19.0

I'm new to use VS code to develop Java. Everything goes fine when creating the simple java program, compiling and debugging. But when I rename the folder that contains java file and debug the java program, it comes an error that shows debugger cannot find java source file. The solution that I found by myself is closing folder and re-import folder again. I'm not sure if there is a bug or I miss some steps to update config in VS code?

Steps to Reproduce:

  1. Here's my simple java program, and it works fine when first created image

  2. My task.json and launch.json for compile and debug image

  3. Then I rename the folder (SimpleJava -> Simple) image

  4. Rebuild Hello.java and debug "Hello", it comes an error. It seems that debugger wants to open the file with the previous folder name. image

Does this issue occur when all extensions are disabled?: No

Copied from original issue: Microsoft/vscode#44706

https://github.com/Microsoft/vscode-java-debug/issues/242

andxu avatar Mar 02 '18 03:03 andxu

I can reproduce this bug, the generated .project refers old file path and doesn't update C:\Users\XXX\AppData\Roaming\Code\User\workspaceStorage\XXX\redhat.java\jdt_ws\jdt.ls-java-project.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>jdt.ls-java-project</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
	</natures>
	<linkedResources>
		<link>
			<name>src/Hello.java</name>
			<type>1</type>
                        <location>c:/work/example/SimpleJava/Hello.java</location>
		</link>
	</linkedResources>
</projectDescription>

It refers old java file c:/work/example/SimpleJava/Hello.java at

c:/work/example/SimpleJava/Hello.java

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Launch)-Hello",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopOnEntry": false,
            "mainClass": "Hello",
            "args": "",
            "classPaths": [
                "${fileDirname}/target"
            ]
        }
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
    {
        "label": "javac",
        "type": "shell",
        "command": "javac ${file}",
        "args": [
            "-d",
            "${fileDirname}\\target"
        ]    ,
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
    ]
}

after renaming the SimpleJava folder to Simple ├───.vscode │ launch.json │ tasks.json │ └───SimpleJava │ Hello.java │ └───target Hello.class

to

├───.vscode │ launch.json │ tasks.json │ └───Simple │ Hello.java │ └───target Hello.class

andxu avatar Mar 02 '18 03:03 andxu

ADD @yhtsao for the original reporter

andxu avatar Mar 04 '18 01:03 andxu

I have the same issue after I modified my java file and class name, the earliest name is "Main". Here are some screenshots: image image I find @andxu in #242 that:

for a temporary solution, try to edit the java file or delete all C:\Users{your user name}\AppData\Roaming\Code\User\workspaceStorage

which folder should I delete on Mac OS X to resolve the issue temporarily if this a bug related to cache?

andyf1111 avatar May 03 '18 05:05 andyf1111

And I have another question, is there any method to customize a target folder where class files generated?

andyf1111 avatar May 03 '18 05:05 andyf1111

@andyf1111 You can set the setting java.project.outputPath, or trigger the command Java: Configure Classpath for a UI based solution

jdneo avatar Jul 05 '21 09:07 jdneo