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

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

error: package net.sourceforge.barbecue does not exist

这怎么可能呢?

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


当前回答

在我的案例中,问题是IntelliJ和settings.xml文件中有不同的存储库目录配置。

检查两个存储库目录是否相同:

IntelliJ(文件>设置>构建,执行,部署>构建工具> Maven)

settings.xml (通常在c:\ users \myuser\。M2或/home/myuser/.m2)

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  ...
  <localRepository>C:\Users\myuser\.m2\repository</localRepository>
  ...
</settings>

修复目录后运行:

为所有项目生成文件夹和更新源

重新导入所有maven项目

其他回答

对我来说奏效了:

再输入 使缓存无效/重新启动 重建项目

我也遇到了同样的问题,通过将设置中的“Maven主目录”从“捆绑”更改为本地安装的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.