Java wildcard classpath

Since JDK 6 you are supposed to be able to write a classpath like

java -cp * foo.Bar

which should set the classpath to contain every .jar ending file in the current directory. But if you do this, it gives you an error that main class “xxx” could not be found, where “xxx” equals the name of the first file in your directory. This is due to some strange shell wildcard expansion (at least on windows, with cygwin installed although i guess it does not matter). So to fix it, you need to set the classpath to something that is an invalid directory (since * can work in normal path names not just classpath). So for example, 

java -classpath .;.\* foo.Bar

works.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s