java 如何在 netbeans 项目的文件夹中添加库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13098363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add libraries in a folder in a netbeans project
提问by Shades88
I am a total java development noob. Thus I don't know how to work with projects in netbeans. Currently I am trying out memcached client for java.
我是一个完全的 Java 开发菜鸟。因此我不知道如何处理 netbeans 中的项目。目前我正在试用 java 的 memcached 客户端。
Now I have created a project. I have downloaded a java memcached client named gwahlin memcached client (can be found here https://github.com/gwhalin/Memcached-Java-Client). Inside it's folder there's this folder structure com/meetup/memcached
and within it are all the required java files. Now I have to import these files in netbeans.
现在我已经创建了一个项目。我已经下载了一个名为 gwahlin memcached 客户端的 java memcached 客户端(可以在这里找到https://github.com/gwhalin/Memcached-Java-Client)。在它的文件夹中有这个文件夹结构com/meetup/memcached
,其中包含所有必需的 java 文件。现在我必须在 netbeans 中导入这些文件。
I tried adding libraries from properties menu of the project. I added this folder, in the libraries within project explorer I can see the folder with the path of this memcached client added. Then when I write import com.meetup.memcached.MemcachedClient;
I get error as that file is not found.
我尝试从项目的属性菜单中添加库。我添加了这个文件夹,在项目资源管理器中的库中,我可以看到添加了这个 memcached 客户端路径的文件夹。然后,当我写入时,import com.meetup.memcached.MemcachedClient;
我收到错误,因为找不到该文件。
I know how to add jar and use it, but what to do in this case? I am totally clueless. Please help me here
我知道如何添加 jar 并使用它,但在这种情况下该怎么办?我完全一窍不通。请在这里帮助我
回答by mohit jain
go to project explorer. Exapnd your current project and simply paste the whole "com" folder in "src" folder. This import will work.
转到项目资源管理器。扩展您当前的项目并将整个“com”文件夹粘贴到“src”文件夹中。此导入将起作用。
回答by vels4j
Here is NetBeans IDE Java Quick Start Tutorial
There are two ways to import classes
导入类有两种方式
- External jars can be added by Project->Properties->Libraries
- By adding classes directly in your project
- 可以通过 Project->Properties->Libraries 添加外部 jars
- 通过直接在您的项目中添加类
回答by Eelke
Are you trying to add the java files from gwhalin as a library? That won't work. Create a seperate Project for gwhalin probably best to use the Java Project with Existing sources for this. Then build your gwhalin project. When you have done that you can add it as a dependency to the libraries of your other project (right click the libraries node and choose Add Project).
您是否尝试将 gwhalin 中的 java 文件添加为库?那行不通。为 gwhalin 创建一个单独的项目可能最好为此使用带有现有源的 Java 项目。然后构建你的 gwhalin 项目。完成后,您可以将其作为依赖项添加到其他项目的库中(右键单击库节点并选择添加项目)。