Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Java CLASSPATH explained

When you run a Java program (be it though the java virtual machine or as a servlet within a web or application container such as Tomcat), it's only the main code (class) that's initially loaded. Any other code (classes) are loaded in dynamically as needed.

Where are these classes loaded from?

They're loaded from EITHER directory structures OR jar files, and the locations of these are in part defaulted (for the standard stuff) and in part defined by the CLASSPATH - an environment variable in which you list the root of the tree in which the JVM (Java Virtual Machine) should start looking. Let's see an example:
   export CLASSPATH=/home/demo/packages:/usr/local/tomcat/shared/lib/wellhouse.jar:.
will cause the JVM to start looking in the packages subdirectory of the demo user's home directory, in a shared directory in your Tomcat installation, and in your current directory.

But that's only where it will start looking. If you're calling in a class called (say) net.wellho.tomcourse.Animal, then the extra package names will be added on to the base path and the actual files looked for on your disc will be:
   /home/demo/packages/net/wellho/tomcourse/Animal.class (an absolute path)
   /usr/local/tomcat/shared/lib/wellhouse.jar ... within in, the file ./net/wellho/tomcourse/Animal.class
   /net/wellho/tomcourse/Animal.class (i.e. below the current directory)


There are even more places that will be searched if you add some import statements to your Java class. Let's say you're loading from a class that includes:
    import net.wellho.general.*;
    import net.wellho.tomcourse.*;
    import org.apache.tomcat.*;

then you'll end up looking in no less that 12 places if you simply call up a class called Animal using the earlier CLASSPATH example:
   /home/demo/packages/Animal.class (an absolute path)
   /home/demo/packages/net/wellho/general/Animal.class (an absolute path)
   /home/demo/packages/net/wellho/tomcourse/Animal.class (an absolute path)
   /home/demo/packages/org/apache/tomcat/Animal.class (an absolute path)
   In /usr/local/tomcat/shared/lib/wellhouse.jar for Animal.class
   In /usr/local/tomcat/shared/lib/wellhouse.jar for net/wellho/general/Animal.class
   In /usr/local/tomcat/shared/lib/wellhouse.jar for net/wellho/tomcourse/Animal.class
   In /usr/local/tomcat/shared/lib/wellhouse.jar for org/apache/tomcat/Animal.class
   ./Animal.class (below the current directory)
   ./net/wellho/general/Animal.class (below the current directory)
   ./net/wellho/tomcourse/Animal.class (below the current directory)
   ./org/apache/tomcat/Animal.class (below the current directory)


Remember too that the Java compiler (known as javac) checks your code - so that it needs access to all necessary classes on the machine you're developing / compiling on to ensure that you're only calling classes - and methods within them - that actually exist. So if you're writing a Servlet, for example, you'll need to have the Servlet API on your CLASSPATH on the development machine and in the development environment, as well as on the test and production servers.
(written 2008-11-26)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
J601 - Java Introduction
  [25] Release numbers - (2004-08-23)
  [111] Training notes available under Open Distribution license - (2004-11-07)
  [124] PHP v Java - (2004-11-20)
  [317] Programming languages - a comparison - (2005-05-20)
  [792] Is Java the right language to learn? - (2006-07-04)
  [871] Java oversold? - (2006-09-19)
  [1049] Java 6, Apache Tomcat 6. - (2007-01-21)
  [1158] Private Java Course - A customer's pictures - (2007-04-22)
  [1418] A Golf Club Decision - Perl to Java - (2007-11-01)
  [1466] Effective Java training - the bootcamp approach - (2007-12-09)
  [1497] Training Season Starts again! - (2008-01-07)
  [1557] Trying out our Java examples on our web site - (2008-02-27)
  [1766] Diagrams to show you how - Tomcat, Java, PHP - (2008-08-22)
  [2115] Finding your java program - the CLASSPATH variable - (2009-04-02)
  [2423] What is a JVM, a JRE, a JDK - components of the core Java Environment - (2009-09-26)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [4332] First Java Application - calculating the weight of a tablecloth - (2014-11-29)

A912 - Web Application Deployment - Upgrading and tuning Tomcat
  [1377] Load Balancing with Apache mod_jk (httpd/Tomcat) - (2007-10-02)
  [1718] Increasing Java Virtual Machine memory for Tomcat - (2008-07-24)
  [2060] Database connection Pooling, SSL, and command line deployment - httpd and Tomcat - (2009-03-01)
  [2082] Jmeter - a first test case - (2009-03-14)
  [3018] Tuning Apache httpd and Tomcat to work well together - (2010-10-27)

A503 - Web Application Deployment - Java - Sourcing, Installing, Initial Testing
  [2079] Java - Memory Allocation and garbage collection - (2009-03-14)
  [2080] Using ApacheBench and jconsole to test and monitor Tomcat - (2009-03-14)
  [2153] Class Loading and Variable Conversion in Java - (2009-05-02)
  [2184] Choosing the right version of Java and Tomcat - (2009-05-16)


Back to
Melksham Hotel Rates
Previous and next
or
Horse's mouth home
Forward to
javax.servlet cannot be resolved - how to solve
Some other Articles
Book now for 2009
Remember Me - PHP
Java - Generics
javax.servlet cannot be resolved - how to solve
Java CLASSPATH explained
Melksham Hotel Rates
Long, Longer, Longest in Java
A Gold Star for First Great Western Customer Service
Ruby, Perl, Linux, MySQL - some training notes
daemons - what is running on my Linux server?
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/1908_Jav ... ained.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb