Ever wish you could set CLASSPATH=c:\someDir\*.jar ?
6
Here's a nifty trick I often use for testing.
Lets say you have a c:\foo\lib directory full of jarfiles for log4j, javamail...whatever.
Modern J2EE containers do a nice job of letting you deploy a jarfile with your code and have a lib directory full of jarfiles like this, but what if you just want to run a quick client from the command line?
Here's what you do:
Lets say you have a c:\foo\lib directory full of jarfiles for log4j, javamail...whatever.
Modern J2EE containers do a nice job of letting you deploy a jarfile with your code and have a lib directory full of jarfiles like this, but what if you just want to run a quick client from the command line?
Here's what you do:
package my.package;
import org.whatever.*;
import org.whateverElse.*; // you can end up with a lot of jarfile dependancies
public class MyClass {
public static void main(String[] args) throws Exception {
// ... code uses whatever & classloader needs those jarfiles
}
}
Normally, you would run it like this:
java -cp c:\foo\lib\whatever.jar;c:\foo\lib\whateverElse.jar ... my.package.MyClass [args]
This can get tedious listing every jarfile, especially if they are all in the same directory anyway. I've always thought you should just be able to say -cp c:\lib\*.jar. That doesn't work, but here's how to get the same effect:
java -Djava.ext.dirs=c:\foo\lib my.package.MyClass [args]






There are drawbacks to using this technique in production systems...
[/quote]
Could you elaborate about what drawbacks we are talking about??