?
Solved

Using classes from another project...

Posted on 2011-10-24
6
Medium Priority
?
287 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:Mike Eghtebas
  • 6
6 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37017704
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.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37017736
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.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37017780
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)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 47

Expert Comment

by:for_yan
ID: 37017819
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).
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37017914
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.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 1000 total points
ID: 37017927

look here for explanation on how to manage dependecies in netbeans:
http://netbeans.org/kb/docs/java/project-setup.html#projects-dependencies
I'm sure you have been already doing it before in all your applets, etc on which we we were working before
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question