Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to check if all *.jars in my CLASSPATH really exists? Automatic check (not manual) possible?

Reply
Thread Tools

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

 
 
Jason Stacy
Guest
Posts: n/a
 
      04-26-2008
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.

 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      04-26-2008
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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      04-27-2008
On 26 Apr 2008 14:39:22 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
.classpath file instead of the CLASSPATH Environment variable. dontspammenow@yahoo.com Java 2 03-02-2008 08:19 AM
problem compiling project, classpath in xml ".classpath" "<classpathentry...>" jameshanley39@yahoo.co.uk Java 2 03-02-2007 12:37 PM
while using javac -classpath some.jar some.java (Where does classpath get stored?) Gabe Java 3 08-27-2004 07:02 PM
CLASSPATH, -cp and -classpath misunderstanding? Flip Java 3 02-09-2004 10:09 PM



Advertisments