How to check if all *.jars in my CLASSPATH really exists? Automatic check (not manual) possible?

Discussion in 'Java' started by Jason Stacy, Apr 26, 2008.

  1. Jason Stacy

    Jason Stacy Guest

    Assume I have a long, long CLASSPATH containing approx 20 (or more) *.jar archives.
    Is there a way to AUTOMATICALLY check if all mentioned *.jar files really exist?

    I could imagine a command (or even java class) which checks this from command line:

    java check_cp &CLASSPATH%

    or similar

    J.
    Jason Stacy, Apr 26, 2008
    #1
    1. Advertising

  2. Jason Stacy

    Arne Vajhøj Guest

    Re: How to check if all *.jars in my CLASSPATH really exists? Automaticcheck (not manual) possible?

    Jason Stacy wrote:
    > Assume I have a long, long CLASSPATH containing approx 20 (or more) *.jar archives.
    > Is there a way to AUTOMATICALLY check if all mentioned *.jar files really exist?
    >
    > I could imagine a command (or even java class) which checks this from command line:
    >
    > java check_cp &CLASSPATH%
    >
    > or similar


    1) Some code for inspiration:

    import java.io.File;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.net.URLDecoder;

    public class CP {
    public static void main(String[] args) throws Exception {
    String cp = System.getenv("CLASSPATH");
    for(String p : cp.split(";")) {
    System.out.println(p + " " + (new File(p)).exists());
    }
    ClassLoader cl = CP.class.getClassLoader();
    if(cl instanceof URLClassLoader) {
    for(URL url : ((URLClassLoader)cl).getURLs()) {
    System.out.println(url + " " + (new
    File(URLDecoder.decode(url.getPath(), "ISO-8859-1"))).exists());
    }
    }
    }

    }

    2) Don't use CLASSPATH env variabel !

    Arne
    Arne Vajhøj, Apr 26, 2008
    #2
    1. Advertising

  3. Jason Stacy

    Roedy Green Guest

    On 26 Apr 2008 14:39:22 GMT, (Jason Stacy) wrote,
    quoted or indirectly quoted someone who said :

    >Assume I have a long, long CLASSPATH containing approx 20 (or more) *.jar archives.
    >Is there a way to AUTOMATICALLY check if all mentioned *.jar files really exist?
    >
    >I could imagine a command (or even java class) which checks this from command line:
    >
    >java check_cp &CLASSPATH%


    Use a Regex split to split your classpath into segments.
    If you have an array of segments and an array of jar names,
    new File (segment, jarname).exists() will form the core of the loop to
    make sure each jar exists once and only once on the classpath.

    see http://mindprod.com/jgloss/regex.html
    http://mindprod.com/jgloss/file.html
    http://mindprod.com/project/pathtool.html
    http://mindprod.com/project/which.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Apr 27, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ike
    Replies:
    6
    Views:
    1,037
    Andrew Thompson
    Sep 24, 2004
  2. Replies:
    5
    Views:
    9,002
  3. JavaEnquirer
    Replies:
    2
    Views:
    502
    JavaEnquirer
    Feb 22, 2006
  4. Lars Willich
    Replies:
    9
    Views:
    590
    Snyke
    Aug 28, 2007
  5. Ulf Meinhardt
    Replies:
    2
    Views:
    1,386
Loading...

Share This Page