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

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

error: package net.sourceforge.barbecue does not exist

这怎么可能呢?

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


当前回答

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

其他回答

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

我重新导入了所有的专家项目。这对我很管用。

这里发生的情况是特定的包在缓存中不可用。重置将有助于解决问题。

File ->使缓存失效/重新启动 转到终端,重新构建项目 。/ gradlew构建

这将再次下载所有丢失的包

package com.example;

import com.sun.jna.Library;
import com.sun.jna.Native;

public class C {
    public interface Kernel32 extends Library {
        public void OutputDebugStringA(String Text);
        public void DebugBreak();
        public void Sleep(int a);
    }

    public static int incint(int in1)
    {
        testpkg.xxxBird.Say("xxxee"); //only use this statement to call external lib
                                      //I don't use "import" statement.
        return in1*2;
    }
}

我正在使用intellij的想法。 您需要在项目依赖项中添加testpkg路径。

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

rm -Rf **/.idea/ 

并重新启动。