如何从 NetBeans 6.8 中的其他项目导入 java 类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2076223/
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 import java classes from other projects in NetBeans 6.8?
提问by John R Doner
I have just started playing with Java, and I really like the language. I am using the NetBeans IDE, and I find one odd oversight. I can create a new class in a project, but NetBeans doesn't appear to support any way to import an existing class into a project.
我刚刚开始玩 Java,我真的很喜欢这门语言。我正在使用 NetBeans IDE,但我发现了一个奇怪的疏忽。我可以在项目中创建一个新类,但 NetBeans 似乎不支持将现有类导入到项目中的任何方式。
I manage to get it done by going to some other project where the desired class already occurs, and then I copy/paste it into the source code folder of the new project, then change the package name at the top of the pasted file to match the package name of the new project.
我设法通过转到已经出现所需类的其他项目来完成它,然后将其复制/粘贴到新项目的源代码文件夹中,然后更改粘贴文件顶部的包名称以匹配新项目的包名。
Is there a nice direct way to do this from the NetBeans interface?
是否有一种很好的直接方法可以从 NetBeans 界面执行此操作?
Thanks for any help on this.
感谢您对此的任何帮助。
采纳答案by Vincent Ramdhanie
In the Projects window you can expand the project that you are working on. Right Click on Librariesand select Add Project.... You will get a dialog allowing you to select another Netbeans Project with the Java classes that you wish to use.
在“项目”窗口中,您可以展开您正在处理的项目。右键单击库,并选择添加项目...。您将看到一个对话框,允许您选择具有您希望使用的 Java 类的另一个 Netbeans 项目。
回答by prakash.panjwani
When you build the java project in netbeans it creates a jar file on the dist folder in the current project directory. You can use this jar file for the other project as a package by adding this as ADD jarin the next project.I have tried this ,i am using my old project jar file for new project development.
当您在 netbeans 中构建 java 项目时,它会在当前项目目录的 dist 文件夹中创建一个 jar 文件。您可以将此 jar 文件作为一个包用于其他项目,方法是在下一个项目中将其添加为ADD jar。我试过这个,我正在使用我的旧项目 jar 文件进行新项目开发。
回答by Chintan Panchal
You have to just make the .jar file of that/those java files which you want to use in another project. right click on file->export->java->.jar then finish.
您只需制作要在另一个项目中使用的那个/那些 java 文件的 .jar 文件。右键单击 file->export->java->.jar 然后完成。
Now you can use these jar into your another project.
现在您可以将这些 jar 用于您的另一个项目。
回答by olawaleazyss
Use the 'Clean and build' your project option from the netbeans application, that creates the 'dist' folder which you are looking for (and obviously can't find because you havn't cleaned&buld)
使用 netbeans 应用程序中的“清理并构建”您的项目选项,这会创建您正在查找的“dist”文件夹(显然无法找到,因为您没有清理&buld)
回答by Dipendra543
The netbeans itself creates .jar files and you can add the jar file to the current project you are working on.
netbeans 本身会创建 .jar 文件,您可以将 jar 文件添加到您正在处理的当前项目中。