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

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

error: package net.sourceforge.barbecue does not exist

这怎么可能呢?

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


当前回答

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

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

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

其他回答

我在更改pom后得到了这个错误,我通过execute修复了它:

mvn idea:module

这对我很有用

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,这是不同的),请确保它是作为相关模块的依赖项包含的。

项目结构->模块->依赖项

以上的解决方案对我不起作用。我必须显式地在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>

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

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路径。