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

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

error: package net.sourceforge.barbecue does not exist

这怎么可能呢?

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


当前回答

如果你不想破坏。idea,你可以尝试:

开放项目结构>模块 将Java文件夹取消标记为源文件夹 应用/重建 然后再次将其标记为源文件夹 重建

其他回答

以上的解决方案对我不起作用。我必须显式地在pom.xml中添加依赖项。

只需将jar添加到resources/library下,然后将其作为依赖项添加到pom.xml中,如下所示:

        <dependency>
            <groupId>your-jar-group-id</groupId>
            <artifactId>artifact-id</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/main/resources/library/name-of-jar.jar</systemPath>
        </dependency>

如果以上方法都不起作用,试试这个方法。

退出IntelliJ,删除所有。idea目录:

rm -Rf **/.idea/ 

并重新启动。

我也遇到了同样的问题,通过将设置中的“Maven主目录”从“捆绑”更改为本地安装的Maven,我解决了这个问题。也许这触发了某种刷新的地方,因为我没有改变这个设置几个月没有任何问题。

现有的13个答案中没有一个对我有用。然而,我可以通过首先删除所有模块来解决这个问题:

打开文件>项目结构… 进入模块选项卡, 选择所有模块,按下移除按钮,

然后从Maven工具窗口中删除所有剩余的Maven模块:

选择所有模块, 右键点击它们, 按删除项目,

然后在项目工具窗口中再次添加它们:

右键单击根目录pom.xml, 按添加为Maven项目,

现在取消Maven工具窗口中任何被忽略的模块:

选择所有被忽略的(灰色)Maven模块, 右键点击它们, 按Unignore,

最后使用Build >重建项目进行重建。这里假设已经进行了mvn清洁安装。

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.