'The import org.xxx cannot be resolved

I'm new to Java, so bear with me...

I have placed a jfreechart-1.5.0.jar file in a lib folder and wanted to do do some imports like this:

import org.jfree.chart.ChartFactory;

But VS Code is complaining: the import org.jfree cannot be resolved.

One thing I have to mention is, that I have created a copy of the project folder in order to try something. Because it worked, I have deleted the original folder and renamed the copy to the name of the original folder.

But now I have the problem that the imports do not work anymore, even it's the same code. I have "cleaned Java language server workspace" but it didn't help.

Is there anything else I have to do? Is the jar import pointing to a certain path / file?



Solution 1:[1]

For Maven project, you can add a dependency by clicking the + icon next to Maven Dependencies node in project view.

enter image description here

If your project is an unmanaged folder without any build tools. You can manage the dependencies by clicking the + icon or the - icon on the Referenced Libraries node or the items under it.

enter image description here

Solution 2:[2]

I had to reference the jar file to the project. Surprisingly the first time it has been referenced automatically, the second time I had to do it manually...

screenshot of VS Code setting

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MingJie-MSFT
Solution 2 Marcello B.