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

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

error: package net.sourceforge.barbecue does not exist

这怎么可能呢?

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


当前回答

以上方法都试过了,都没用。 最后运行maven清洁安装就解决了!

其他回答

对于偶尔需要做Java工作的人来说,这是非常烦人的。不可避免地,自从我上次在IntelliJ中运行我们的服务器以来,已经添加了包,它将无法构建。我发现了一个似乎更简单的解决方案:不要在IntelliJ内构建。通过Maven从命令行构建,然后确保运行配置没有将构建列为“启动前”任务。

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

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

menu -> build -> Rebuild Project

对我很有用

(没有此步骤无效缓存没有帮助)

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.

Maven重新导入,重新构建和无效缓存不工作。我通过打开一个终端并在根文件夹项目中执行maven clean install解决了这个问题。(IntelliJ被打开,我能够看到IDE更新和触发驯鹿,而maven正在做他的工作)