Using classes from another project...

What is JAR and how do I add a file/project to libraries so I can use a certain class from another project.

I am using netbeans.

Thank you.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
for_yanConnect With a Mentor Commented:

look here for explanation on how to manage dependecies in netbeans:
I'm sure you have been already doing it before in all your applets, etc on which we we were working before
You can put the source code of the class from another project under the src folder of your project (in the appropriate place according to package) and when you them package jar out of your project, it will package this additiionaal class together with all other classes.
In case you do not have source code of that class, you can put the class file itself in the appropriate place (according to package) in your target structure.
Or you can put in any place (according to package of course) and add the root class folder of that additional folder tree the same way you add dependencies - you can either add jar dependenies, or dependencies on class folders.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

What is JAR ?
Compressed and pckaged into archiove folder directory tree whioch contains class files. It can be put in the classpath environement variables and will be used by JVM to retrive required classes the same way as expanded class folder durectory would have been used if it were not compressed to file but used as an actual class folder directory tree.
The compressioin format of Jar is iodenticalk to zip. You can eeven rename it to zip and then open woith winzip (and zips can be used in clsspath the same way as jars by the way also)
To summarize - jar is directory tree of class folders containing java class files placed according their package names and then packaged into one file.
For all practicalk purposes jar file acts exactly as the tree of directories with class files and can be added to project by adding jar file to the list of jars or top level class folders and assigning this list to env variable CLASSPATH prior to execition of java program (or adding dependecy to project in the IDE).
It is also good to know that together with other command line tools coming with JDK (such as javac, java, etc)
there comes the command line tool called jar which acts the same way as command line zip program and packages foldeers
and adds/removes files into jar archives using switches/options and file names as command  line arguments
In practice no  one uses this comand line tool because folks are developing in IDEs and each IDE has a way to
create the jars through their menu, whjich is much more convenient.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.