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





PostPosted: 2008-4-26 22:39:00 Top

java-programmer, How to check if all *.jars in my CLASSPATH really exists? Automatic check (not manual) possible? 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.

 
Lion-O





PostPosted: 2008-4-26 23:32:00 Top

java-programmer >> How to check if all *.jars in my CLASSPATH really exists? Automatic check (not manual) possible? > 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 doubt it. This is because Java doesn't really care about the jarfiles
themselves, only the classes which they contain. It will only try opening them
whenever it needs to access a certain class.

So I think that the only way to be sure is manually listing the classpath, then
grabbing all file entries and finally start checking up if those exist.

Groetjes, Peter

--
.\\ PGP/GPG key: http://www.catslair.org/pubkey.asc

 
Arne Vajh鴍





PostPosted: 2008-4-26 23:48:00 Top

java-programmer >> How to check if all *.jars in my CLASSPATH really exists? Automatic check (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
 
 
Roedy Green





PostPosted: 2008-4-27 16:15:00 Top

java-programmer >> How to check if all *.jars in my CLASSPATH really exists? Automatic check (not manual) possible? On 26 Apr 2008 14:39:22 GMT, email***@***.com (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