Java,如何在netbeans中添加库文件?

发布于 2024-11-04 20:55:57 字数 195 浏览 0 评论 0原文

我是 Netbeans IDE 和 Java 的新手。我有一个 java 项目显示很多编译错误:

can not import "org.apache.commons.logging.Log"

有人可以帮我解决这些错误吗?How do I add library files in Netbeans IDE?

I am new to the Netbeans IDE and Java. I have a java project that shows lot of compilation errors:

can not import "org.apache.commons.logging.Log"

Can somebody please help me with these errors, How do I add library files in Netbeans IDE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

这个俗人 2024-11-11 20:55:57

NetBeans 6.8 中的快速解决方案。

在“项目”窗口中右键单击缺少库的项目名称 ->属性-> “项目属性”窗口打开。在类别树中选择“库”节点 ->在“项目属性”窗口的右侧,按“添加 JAR/文件夹”按钮 ->选择您需要的罐子。

您还可以查看我的简短视频操作方法

Quick solution in NetBeans 6.8.

In the Projects window right-click on the name of the project that lacks library -> Properties -> The Project Properties window opens. In Categories tree select "Libraries" node -> On the right side of the Project Properties window press button "Add JAR/Folder" -> Select jars you need.

You also can see my short Video How-To.

江南烟雨〆相思醉 2024-11-11 20:55:57

如何将公共库导入到 netbeans 中。

  1. 评估 NetBeans 中的错误消息:

    java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    
  2. NoClassDeffFoundError 表示您使用的代码中的某个地方,一个方法调用了另一个方法,该方法调用了一个无法找到的类。那么这意味着您的代码执行了以下操作: MyFoobarClass foobar = new MyFoobarClass() 并且编译器会感到困惑,因为没有任何地方定义此 MyFoobarClass。这就是您收到错误的原因。

  3. 要知道下一步该怎么做,您必须仔细查看错误消息。 “org/apache/commons”一词让您知道这是提供您所需工具的代码库。您可以选择,要么导入 apache commons 中的所有内容,要么只导入 LogFactory 类,或者可以在两者之间做一些事情。例如,只需获取 apache commons 的日志记录位即可。

  4. 你会想要走中间路线并获得公共日志记录。绝佳的选择,启动谷歌并搜索apache commons-logging。第一个链接将您带到 http://commons.apache.org/proper/commons-logging/ 。前往下载。在那里您会找到最新的。如果您的项目是在旧版本的 commons-logging 下编译的,那么请使用相同的旧版本,因为如果您使用较新的版本,则代码可能会失败,因为新版本不同。

  5. 您需要下载commons-logging-1.1.3-bin.zip或类似的东西。读一下这个名字的意思。 .zip 表示它是压缩文件。 commons-logging 意味着这个应该包含您想要的 LogFactory 类。中间的1.1.3表示就是这个版本。如果您正在编译旧版本,则需要将它们匹配,否则您将面临由于升级而发生的更改而导致代码无法正确编译的风险。

  6. 下载该 zip 文件。解压它。搜索以 .jar 结尾的内容。在 netbeans 中右键单击您的项目,单击属性,单击库,单击“添加 jar/文件夹”并导入这些 jar。保存项目并重新运行,错误就会消失。

二进制文件不包含源代码,因此您将无法深入了解调试时发生的情况。作为程序员,您应该下载 apache commons 的“源代码”并从源代码进行编译,自己生成 jar 并导入它们以获取经验。您应该足够聪明,能够理解并纠正您正在导入的源代码。这些古老版本的 apache commons 可能是在旧版本的 Java 下编译的,所以如果你回溯太久,它们甚至可能无法编译,除非你在旧版本的 java 下编译它们。

How to import a commons-library into netbeans.

  1. Evaluate the error message in NetBeans:

    java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    
  2. NoClassDeffFoundError means somewhere under the hood in the code you used, a method called another method which invoked a class that cannot be found. So what that means is your code did this: MyFoobarClass foobar = new MyFoobarClass() and the compiler is confused because nowhere is defined this MyFoobarClass. This is why you get an error.

  3. To know what to do next, you have to look at the error message closely. The words 'org/apache/commons' lets you know that this is the codebase that provides the tools you need. You have a choice, either you can import EVERYTHING in apache commons, or you could import JUST the LogFactory class, or you could do something in between. Like for example just get the logging bit of apache commons.

  4. You'll want to go the middle of the road and get commons-logging. Excellent choice, fire up the google and search for apache commons-logging. The first link takes you to http://commons.apache.org/proper/commons-logging/. Go to downloads. There you will find the most up-to-date ones. If your project was compiled under ancient versions of commons-logging, then use those same ancient ones because if you use the newer ones, the code may fail because the newer versions are different.

  5. You're going to want to download the commons-logging-1.1.3-bin.zip or something to that effect. Read what the name is saying. The .zip means it's a compressed file. commons-logging means that this one should contain the LogFactory class you desire. the middle 1.1.3 means that is the version. if you are compiling for an old version, you'll need to match these up, or else you risk the code not compiling right due to changes due to upgrading.

  6. Download that zip. Unzip it. Search around for things that end in .jar. In netbeans right click your project, click properties, click libraries, click "add jar/folder" and import those jars. Save the project, and re-run, and the errors should be gone.

The binaries don't include the source code, so you won't be able to drill down and see what is happening when you debug. As programmers you should be downloading "the source" of apache commons and compiling from source, generating the jars yourself and importing those for experience. You should be smart enough to understand and correct the source code you are importing. These ancient versions of apache commons might have been compiled under an older version of Java, so if you go too far back, they may not even compile unless you compile them under an ancient version of java.

携余温的黄昏 2024-11-11 20:55:57

在 Netbeans 8.2

1.从网络源下载二进制文件。
Apache Commos 位于:[http://commons。 apache.org/components.html][1]
在这种情况下,您必须在“组件”菜单中选择“日志记录”,然后点击“发布”部分中的下载链接。直接 URL:[http://commons.apache.org/正确/commons-logging/download_logging.cgi][2]
对我来说,正确的下载是来自二进制文件commons-logging-1.2-bin.zip文件。

2.解压缩下载的内容。现在,您可以在从 zip 文件创建的目录中看到几个 jar 文件

3.将库添加到项目中。右键单击项目,选择“属性”,然后单击“库”(位于左侧)。单击“添加 Jar/文件夹”按钮。转到之前解压的内容并选择正确的 jar 文件。单击“打开”,然后单击“确定”。库已加载!

In Netbeans 8.2

1. Dowload the binaries from the web source.
The Apache Commos are in: [http://commons.apache.org/components.html][1]
In this case, you must select the "Logging" in the Components menu and follow the link to downloads in the Releases part. Direct URL: [http://commons.apache.org/proper/commons-logging/download_logging.cgi][2]
For me, the correct download was the file: commons-logging-1.2-bin.zip from the Binaries.

2. Unzip downloaded content. Now, you can see several jar files inside the directory created from the zip file.

3. Add the library to the project. Right click in the project, select Properties and click in Libraries (in the left side). Click the button "Add Jar/Folder". Go to the previously unzipped contents and select the properly jar file. Clic in "Open" and click in"Ok". The library has been loaded!

童话 2024-11-11 20:55:57

适用于 Netbeans 2020 年 9 月版本。 JDK 11

(仅建议 Gradle 项目使用)

1.src/main/java< 中创建 libs 文件夹< /code> 项目的文件夹

2. 复制其中的所有库 jar

3. 在项目窗口的 files 选项卡中打开 build.gradle项目的根

4.正确的主类(我的是mainClassName = 'uz.ManipulatorIkrom'

5.依赖项 添加下一个字符串:

apply plugin: 'java' 
apply plugin: 'jacoco' 
apply plugin: 'application'
description = 'testing netbeans'
mainClassName = 'uz.ManipulatorIkrom' //4th step
repositories {
    jcenter()
}
dependencies {
    implementation fileTree(dir: 'src/main/java/libs', include: '*.jar') //5th step   
}

6. 保存、清理构建,然后运行应用程序

For Netbeans 2020 September version. JDK 11

(Suggesting this for Gradle project only)

1. create libs folder in src/main/java folder of the project

2. copy past all library jars in there

3. open build.gradle in files tab of project window in project's root

4. correct main class (mine is mainClassName = 'uz.ManipulatorIkrom')

5. and in dependencies add next string:

apply plugin: 'java' 
apply plugin: 'jacoco' 
apply plugin: 'application'
description = 'testing netbeans'
mainClassName = 'uz.ManipulatorIkrom' //4th step
repositories {
    jcenter()
}
dependencies {
    implementation fileTree(dir: 'src/main/java/libs', include: '*.jar') //5th step   
}

6. save, clean-build and then run the app

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文