Setting the class path: Rookie Question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Setting the class path: Rookie Question

  1. #1
    Andrew Jay Guest

    Setting the class path: Rookie Question


    I'm another programmer making the switch to Java. I'm feeling a little stupid
    since I can't seem to figure out how to set the classpath. I have a third
    party jar file that I want to import into my class. But when I go to compile
    the class it cannot find the jar files. I set the classpath (set CLASSPATH=.;c:\java\xerces\jar;
    %CLASSPATH$) but this didn't work. Finally I unzip the jar file in the same
    directory and that did the trick but I really want to know how to do it "properly".
    Any help would be greatly appreciated.

  2. #2
    GregD. Guest

    Re: Setting the class path: Rookie Question


    "Andrew Jay" <ajay@home.com> wrote in message news:3bf42048$1@147.208.176.211...

    the class it cannot find the jar files. I set the classpath (set CLASSPATH=.;c:\java\xerces\jar;
    %CLASSPATH$) but this didn't work. Finally I unzip the jar file in the same


    if you are trying to prepend your c:\... string onto the existing CLASSPATH envar try this
    set CLASSPATH=.;c:\java\xerces\jar;%CLASSPATH%;




  3. #3
    Kyle Gabhart Guest

    Re: Setting the class path: Rookie Question


    "Andrew Jay" <ajay@home.com> wrote:
    >
    >I'm another programmer making the switch to Java. I'm feeling a little stupid
    >since I can't seem to figure out how to set the classpath. I have a third
    >party jar file that I want to import into my class. But when I go to compile
    >the class it cannot find the jar files. I set the classpath (set CLASSPATH=.;c:\java\xerces\jar;
    >%CLASSPATH$) but this didn't work. Finally I unzip the jar file in the

    same
    >directory and that did the trick but I really want to know how to do it

    "properly".
    > Any help would be greatly appreciated.


    Andrew,

    No need to feel stupid, the classpath is one of the trickiest things to get
    a handle on in Java. There are three ways of getting your desired classes
    into the classpath:

    1) Unzip/Unjar the files into the same directory -- this is a hassle and
    not a very manageable solution
    2) Indicate the location of the JAR files in your classpath -- the reason
    this didn't work for you, is that although you have included the path to
    your JAR directory, Java's classloader is not designed to search every JAR
    and ZIP file it comes across and then load any classes found. You should
    think of JAR and ZIP files as directories in and of themselves. Unless you
    indicate to the class loader that you want a particular directory to be included,
    it won't include that directory. What you need to do instead, is mention
    each JAR or ZIP file by name:

    CLASSPATH=.;c:\java\xerces\jar\Xerces.jar;%CLASSPATH%

    3) Utilize Java 2's Extensions Directory -- With the release of Java 2, a
    new means of including JAR and ZIP files into the runtime classpath was added.
    If you place such files into this directory, then the classloader will search
    all JAR and ZIP files and include their contents in the classpath. That
    directory is located at: %JAVA_HOME%\jre\lib\ext

    Let me know if there is anything else that I can clarify.

    Happy Coding!

    Cordially,

    Kyle Gabhart
    DevX Java Pro


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center