Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import java classes from other projects in NetBeans 6.8?

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.

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?

Thanks for any help on this.

like image 228
John R Doner Avatar asked Jan 16 '10 04:01

John R Doner


People also ask

Can you import a class from another project Java?

Yes. In the Project Explorer right click on it and select Properties, there go to Java Build Path and select Projects tab. Add your other project here, now you're able to use the classes from it in your current project.

How do I import and run a Java project in NetBeans?

Go to Main Menu -> File -> Import Project -> from ZIP. If you have Java project depending on external Libraries, Netbeans will highlight & ask for "Resolving problems" in project, click on resolve, provide location in your file system containing required library files . e.g JARs etc & you will be good to go.

How do I Auto import in NetBeans?

"Alt + Shift + I" fixes selected class's import. When there is no selection Netbeans tries to fix the import for the element, the cursor is on. Use Ctrl + Shift + I to fix all imports for the whole file. Save this answer.


2 Answers

In the Projects window you can expand the project that you are working on. Right Click on Libraries and select Add Project.... You will get a dialog allowing you to select another Netbeans Project with the Java classes that you wish to use.

like image 177
Vincent Ramdhanie Avatar answered Nov 20 '22 05:11

Vincent Ramdhanie


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.

Now you can use these jar into your another project.

like image 33
Chintan Panchal Avatar answered Nov 20 '22 05:11

Chintan Panchal