vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Warning: Classpath is incomplete. Only syntax errors will be reported.

Open leizongmin opened this issue 10 years ago • 22 comments

I set java.home to "/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home", when I open a java file, the vscode shows the warning message "Classpath is incomplete. Only syntax errors will be reported.", what's wrong? How can I fix this issue?

This warning message is from this file: https://github.com/gorkem/java-language-server/blob/74efc7ac1d9c9abb6728864111e33b1eb4d5e483/org.jboss.tools.vscode.java/src/org/jboss/tools/vscode/java/internal/handlers/DocumentLifeCycleHandler.java#L114

Environment
  • Operating System: macOS Sierra 10.12.1
  • JDK version: 1.8.0_102
  • Visual Studio Code version: 1.7.2
  • Java extension version: 1.8.0_102
Steps To Reproduce
  1. on settings.json file, set java.home to "/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home"
  2. reload window
  3. open a java file

leizongmin avatar Nov 27 '16 09:11 leizongmin

So am i,but my operating system is win10.

wzdnzd avatar Nov 27 '16 11:11 wzdnzd

I use Win10 and I have set up both my PATH & CLASSPATH properly. But I get the same warning message on starting VSC.

deepanjannag avatar Nov 27 '16 21:11 deepanjannag

This warning is displayed when you open a single java file, because at that point, no classpath can be configured thus no information on types other than the default JDK can be provided. In that case, only syntax errors are reported. Else you'd get compilation errors all over the place. Javadoc and Navigation to classes from the JDK are available.

You need to open a folder containing a pom.xml, or at least default eclipse setting files, so that a complete classpath and project hierarchy can be set.

fbricon avatar Nov 28 '16 15:11 fbricon

Yes, I opened a folder that contains a pom.xml file, it did not show this warning again.

I think the warning message would be more friendly, such as Cannot find pom.xml or eclipse setting files. Classpath is incomplete. Only syntax errors will be reported. will help people quick understand what's wrong with it.

leizongmin avatar Nov 28 '16 15:11 leizongmin

Is there a way to disable the warning? I often use VSCode when I want to look at single files outside of a project and in that case the warning is annoying. Maybe it could be changed to a warning in the status bar?

peterzeller avatar Dec 02 '16 08:12 peterzeller

@peterzeller we opted for the warning to display because we think that linked mode can throw a developer that uses vscode to build an application off track. However, I do agree that the warning will become annoying after a while. Alternates that comes to my mind

  • A new setting to suppress warnings.
  • Show warnings for first n times and switch to status bar.

gorkem avatar Dec 02 '16 14:12 gorkem

If you do need to show the warning then at least making it so that it can be dismissed for the whole of the remainder of the current session until VS Code is restarted would make it less annoying.

NathanJPhillips avatar Dec 07 '16 17:12 NathanJPhillips

I just got the same unfriendly message. Is the intention to let it stay like that?

As insight:

  • "Classpath is incomplete". Huh? What is it lacking? What is a complete classpath?
  • "Only syntax errors will be reported". Huh? What am I missing? What other kinds of errors can I get?

dasilvacontin avatar Apr 09 '17 20:04 dasilvacontin

Does https://github.com/redhat-developer/vscode-java/wiki/%22Classpath-is-incomplete%22-warning help? We should probably link to that page directly from the warning

fbricon avatar Apr 09 '17 21:04 fbricon

@fbricon The link explains pretty well what to do. The problem is that I feel left alone with how to do it. I am only writing small snippets and tests, thus I have all my files in the current directory. I don't need a full bloated pom.xml After looking around with pom.xml I only found examples for classpath = "src"

Wouldn't it make sense to assume curr_directory is the classpath for standalone files?

EldarKersebaum avatar May 19 '17 13:05 EldarKersebaum

@EldarKersebaum you should be able to get content-assist and navigate between classes in the same folder with ctrl+click, provided these files have been opened once in vscode. This is a current technical limitation. But if you click on Don't show again, that should be enough for a small number of classes.

Please open a separate feature request if you think we could improve that

fbricon avatar May 19 '17 14:05 fbricon

Just leaving a note here for people who are trying to make this work...

The key is to not think of this as Java support for VS Code. It's an adapter to make Eclipse's Java support work with VS Code.

If you try to make it do anything but the things it explicitly support (reading eclipse project files and some other things) you are in for a world of hurt. Instead, just install Eclipse temporarily, Google how to import your project into Eclipse, and then take the .project and .classpath files generated by Eclipse and put those in your project so VS Code can find and use them.

Getting a project with an Ant build to work with VS Code was a total nightmare until I tried this approach. Just a couple of clicks to import the ant project into Eclipse, then copy the project files and bam everything just works.

Maybe in the future this plugin will also borrow Eclipse's excellent project import features, but until then don't waste your time trying to make your project work with VS Code directly and go through Eclipse project import instead.

rvolgers avatar Sep 14 '17 10:09 rvolgers

Cheers to rvolgers!

The readme is misleading:

  • Maven pom.xml project support
  • Basic Gradle Java project support

Actually, the plugin supports Eclipse files:

.classpath
.project
.settings/org.eclipse.jdt.core.prefs

And it would be worth mentioning this in the readme.

Regards Peter

pbberlin avatar Dec 28 '17 16:12 pbberlin

Then are there any plans to support Gradle projects separately from eclipse projects? When I create a build.gradle file, vscode generates eclipse files even though it's not an eclipse project.

cjsimon avatar Jan 01 '18 02:01 cjsimon

Also it would be nice if it would follow VS code conventions: Put the plugin configuration into .vscode folder, do not litter my project with .classpath, .project, .settings.

matyasforian avatar Feb 28 '18 15:02 matyasforian

because we're using an headless eclipse process behind the scenes, we have no way to control where those .classpath, .project, .settings. files can be stored. It's unlikely to change unfortunately.

fbricon avatar Feb 28 '18 15:02 fbricon

#1094 and same at https://github.com/microsoft/vscode-java-dependency/issues/189 Project working on eclipse , but not in VSCODE. more detail in above link.

sandeepamilineni avatar Oct 27 '19 10:10 sandeepamilineni

@leizongmin try disable the extension "Language Support for Java(TM) by Red Hat"; then restart vscode, the extension will auto enable.

dbthinking avatar Nov 19 '19 17:11 dbthinking

You will have to set up the classpath. So, try this --> https://www.geeksforgeeks.org/how-to-set-classpath-in-java/ This has helped me with the same warning.

Let me know if this works for you.

Sushmita-kan avatar May 01 '21 11:05 Sushmita-kan

So, I've found a solution (probably?) for this. Might be a silly one but it works for me.

Go ahead and delete the workspaceStorage data for your project every time you encounter this error.

How to do that?

  1. Hit Ctrl/Cmd + Shift + P .
  2. Type in Java: Configure Classpath .
  3. Head over to the path specified in the Output section.
  4. Keep navigating out of the directories until you're inside the workspaceStorage directory.
  5. Your current workspaceStorage will be under a specified ID. Go ahead and delete everything inside it so that the next time you open your project, the classpath settings will be built from scratch.
  6. You can do this every time you encounter classpath errors like these. Cheers!

alpha037 avatar May 05 '21 15:05 alpha037