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

J

Jason Stacy

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.
 
A

Arne Vajhøj

Jason 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%

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
 
R

Roedy Green

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top