16

I got an error when trying to debug java code in visual studio code. The error is below

build failed, do you want to continue?

I have tried clearing the workspace, but it doesn't work. Please, how can I fix this issue?

Gama11
  • 28,518
  • 9
  • 66
  • 91
Liu Bei
  • 477
  • 2
  • 9
  • 18
  • 1
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, **a specific problem or error and the shortest code necessary to reproduce it in the question itself.** Questions without a clear problem statement are not useful to other readers. – Compass May 21 '18 at 18:18
  • In order to debug you need some code that runs. A failed build means the code cannot be compiled => there is nothing to run. Or maybe there is a previous successful build and there is something to run and debug but it is not the current code. You don't want to continue, you have to fix the errors first. – axiac May 25 '18 at 11:09
  • I know this is not an answer, but it is a solution - I got past this by simply deleting and recreating my workspace... – Greg May 07 '20 at 15:14
  • @Compass: Sometimes people with 5000+ points are simpy too eager to call for discipline? Though I understand why you wrote this, it is still strange if this comes 1 min after the question, and then it was wrong because this question was not depending on code and could not have been stated any better. It was exactly this question with all of the answers that have helped me. – questionto42standswithUkraine May 15 '20 at 16:22
  • 1
    @Lorenz this was the standard message reply prompt for helping users improve questions in 2018, and in no place did I ever call for discipline, only tell the user to provide additional information to help with debugging. At this point in time, there was no evidence of a dependency library error, and no real evidence to indicate as such. When the accepted answer itself states the OP is not clear enough, that usually means that the question could be improved. – Compass May 16 '20 at 17:13
  • @Compass You are right. Thank you for your explanation. – questionto42standswithUkraine May 18 '20 at 10:31

8 Answers8

12

Update. Problem solved I resolved this issue by clearing the workspace cache in VS code. Here is a link to the relvant page: VSCODE Clean Workspace Directory . I had renamed a number of folders, class names and packages. Apparently the RedHat-Developer plugin managed to get out of sync. The .classpath file was out of sync with the POM file. Wiping out the workspace cache caused the plugin to recreate project data from the maven spec. Problem solved. Not sure but if anyone from the RedHat project reads this, it looks to me like a bug, or deficiency. In any event it can be worked around.

Original answer follows:

I think Liu Bei was not clear enough. I am experiencing the same issue. I have a project that builds perfectly in Maven and when I launch the debugger in Visual Studio Code this notification appears in the lower right-hand corner of the VSCode window.

enter image description here

Obviously the "Debugger for Java" extension thinks there is a build problem. However there are no errors reported in the PROBLEMS, OUTPUT, DEBUG CONSOLE or TERMINAL tabs.

The project builds, and packages in Maven just fine and it can be debugged in attach mode which is tedious at best.

There is something going on in VSCode that's not being reported anywhere that I can find. I suspect the RedHat VSCode plugin for Java is in the mix but need help figuring out how to work around the issue.

I have to say that we are spending way too much time resolving issues with tools and dependencies and not enough time on the app. The project we are working on is intended for open source distribution. The Spring Framework seems ideal for our purposes but the tooling, not so much. We are not very far into the project and I am already receiving pressure to switch to .NET core MVC.

Really need a little help...

BigTFromAZ
  • 603
  • 7
  • 20
  • Thank you a lot, this is what I am expecting. – Liu Bei Jul 27 '18 at 14:32
  • 1
    I have same issue, I have an Multiple project I need to run one project at a time – Sajith Apr 05 '19 at 04:46
  • Solution listed works. In particular opening Cmd Pallette and running the following: Java: Clean the Java language server workspace – Mike_L Jun 13 '19 at 13:36
  • This is a life saver. Eclipse often gets out of sync and sometimes I had to delete my workspace and rebuild it all. It seems that the Java plugin for vscode has the same problem, but at least this solution is quick and relatively simple. – Mike Stoddart Jul 03 '19 at 11:45
7

So this didn't work for me, but I found out what did.

First of all looking at the Java Dependencies plugin gave me a hint that something was out of sync. The name of my application (artifact) did not match the name in the Java Dependencies tree view.

This was fixed by clearing the VSCode workspaceStorage folder completely!

This folder was in my case located in (Windows 10):

C:\Users\<myuser>\AppData\Roaming\Code\User\workspaceStorage

If you can't find it at this location, simply search for the folder workspaceStorage.

Next press ctrl + shift + p (in my case) to open the VSCode action prompt. Then choose the command:

Java: Open Java Language Server Log File

This will open a log file which is normally not displayed when building your Java code, and will tell you exactly what went wrong with the build.

In my case it was a conflict as I had two AppConfig.java files, one in main and one in test. Maven handles this fine, but apparently the VSCode Java builder does not.

Obviously these are bugs in the plugins which I will report to the GitHub contributors, but for now we will have to live with a little manual work.

Still I hope this helps all of you frustrated VSCode Java developers out there.

Michael
  • 347
  • 2
  • 10
  • I also had to open each project in its separate folder to get rid of the error message, as @Sajith wrote. I used your recommended log file (but: no clearing of the workspace needed for that), searching upwards from the bottom until I found the first error. In my case, I had a main folder opened in VS code with 2 subfolders A4 and A5, both separate projects. I was running A5 build and got the error from A4 build: `!MESSAGE Error occured while building workspace. Details: message: The declared package "" does not match the expected package "A4"; code:[here link to first file in A4]` – questionto42standswithUkraine May 15 '20 at 16:28
  • I still had other project file related errors after this. Then I cleared the workspace incl. restart, and still errors. Then it showed errors for only those classes that I use in the main(). That made me curious. I started with an empty main(), commenting out the whole main() body. No errors. I added line by line, but you can also add all lines at once: no errors. Seems as if the project was reset with this.empty main(), only loading the local package and import commands. – questionto42standswithUkraine May 15 '20 at 18:15
3

It worked for me to change the user setting in setting.json to "java.debug.settings.forceBuildBeforeLaunch": false on vscode, which will disable the check before run/debug.

0

Build failed error in VsCode

This error occurs because in your workspace folder the other source code has some errors in it.

So create a new folder and make it as a workspace folder and then write your codes in that folder and run it.

I had that error also and it's work for me, so check for yours.

Vishal
  • 1
0

Using OSX I managed to overcome this problem, that you can either access from your Terminal or simply use short cut (command shift and c) select Base System then Library, look for the Java folder then click on the Java Virtual Machines folder. Check if is there the actual version of jdk (most up to date). I've noticed that I had two jdk folders one probably inherited from a previously installation and the most up-to-date jdk-15. Dragged jdk-14 to the bin enter password, close finder and restart VSCode. It works fine now!

0

First of all, check carefully the errors on VS Code log and try to not get biased by the community common errors. To do this press ctrl + shift + p to open the VSCode action prompt. Then choose the command:

Java: Open Java Language Server Log File

By doing this you can find the exactly exception that is happening. In my case I was having two exceptions:

java.lang.NoClassDefFoundError: javax/annotation/processing/AbstractProcessor

And

java.lang.NoClassDefFoundError: com.demo.myapplication

So, I was biased to think that error was related to Java version or stuff like that, but it was related to a lombok extension installed on VSCode.

In the end I found this thread and tested this solution and it worked like a charm.

Here is the solution explained by him:

Finally I got it woking. The issue is with the additional argument -Xbootclasspath added by the lombok extension to the java.jdt.ls.vmargs. I figured it out by integrating the lombok with eclipse and opened the eclipse.ini file for the changes.

I uninstalled the vscode-lombok extension; I downloaded the lombok.jar (version 1.18.6) file from https://projectlombok.org/download; In VSCode, in settings.json, for java.jdt.ls.vmargs key, I added the argument -javaagent:"PATH_TO_DOWNLOADED_LOMBOK_JAR_FILE"

A last necessary step (missed by the github guy) is to reinstall lombok extension.

rafalimaz
  • 50
  • 8
0

For me, the problem was that I created a folder within a folder for arranging my java program files with the reference to data structures. In the log file, it was showing that the .java file in the inner folder is not on its project's build path.

Just after deleting that folder and completely deleting all the files in the workspace folder manually in the location C:\Users<myuser>\AppData\Roaming\Code\User\workspaceStorage, this problem was solved!

-1

I had the same problem. I just downloaded this provided by vs code the Java Extension Pack click on link, download and open it.it will automatically configure vs code for java. link below...

https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack