Mike Eghtebas
asked on
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.
I am using netbeans.
Thank you.
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.
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.
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)
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).
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.