我正在尝试使用烧烤条形码打印库。我通过project structure add library成功将库添加到IntelliJ。然后我导入了包并编写了方法,这没有给我任何错误。这些包在类中可用。

但是当我编译时,它会给我一个错误:

error: package net.sourceforge.barbecue does not exist

这怎么可能呢?

我在ubuntu中编码,还有其他地方需要添加库吗?


当前回答

我的单元测试也遇到了同样的问题。我在我的主分支上创建了测试,在早期,无论我使用的是哪个分支,一切都运行良好。但是当我再次切换到主分支时,测试不再工作了。 帮助我的是:

关闭intellij ->从目录中删除。idea文件->再次通过pom.xml打开项目(idk如果它与你打开项目的方式有关,但第一次当我尝试通过intellij正常打开它时,它仍然不工作)->从右菜单重新加载所有maven项目->重建项目,就是这样,现在一切都工作了

其他回答

如果你尝试了建议的方法,仍然没有机会,请确定你的订单:

删除你的。idea/ 无效和重新启动缓存之后 从maven工具导入maven项目

如果你没有在删除你的.idea/后无效并重新启动缓存,Intellij会继续生成它,这在我的情况下是错误的。

I created two new classes under a new package and used it in rest of the code, Intellij was able to resolve these no red highlights were shown in the intellij editor. While building it was showing package doesn't exist error. I tried everything from gradle clean build, rebuild project, clear .idea and .gradle and reimporting the project, clearing the gradle local cache but nothing was working. Finally I refactored the name of the new package and this time intellij was able to recognize the new classes and it started working.

只是重新导入不起作用。下面的方法对我很有效。

File ->使缓存失效/重新启动

Then

Build ->重建项目

这将重新导入maven项目。

注意:您需要使缓存无效并重新构建项目。

对我来说,唯一有效的方法是:

mvn idea:idea

好处是您不必删除.idea文件夹或.iml文件,从而丢失所有配置。一切都会被保存下来。

(可能有些类似gradle的想法也适用于gradle)。

无效缓存为我工作,但它太长时间来恢复缓存,所以我没有耐心等待它。我找到了另一种方法来解决我的问题。“修复IDE”步骤3(删除包搜索项目缓存)为我完美地工作