0

I am inside a E:/foo/bar folder inside windows environment. I have a jar file as E:/foo/bar/a.jar. Also inside foo/bar there are lot of jar files. Also under the foo/bar there is another directory called ext. It also includes lot of jar files.

I want to run the a.jar with those jars included in the class path(both current directory and ext directory). So I used this.

java -jar a.jar -classpath *:/ext/*

This didn't work. I didnt add any entries in the MANIFEST.MF in a.jar thinking that this will be fetched from the -classpath entry. What am I doing wrong here?

Thank you

James Jithin
  • 10,183
  • 5
  • 36
  • 51
Dilshan
  • 3,231
  • 4
  • 39
  • 50

1 Answers1

1

The -classpath option is ignored if -jar is specified.

Two possible course of action I can see:

  1. Put a manifest in the main Jar that does specify the other Jars.
  2. Specify the class-path at run-time.
    1. Drop the -jar option of the invocation.
    2. Specify all the dependent Jars
    3. Add the fully qualified class name to the end of the command, something like
      java -classpath *:/ext/* com.our.MainClass
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Thanks. Your 3) doesnt work. It throws Exception in thread "main" java.lang.NoClassDefFoundError: test.test.MyClass – Dilshan Jan 25 '12 at 11:52
  • 1
    I'm not sure of the wild-card characters, I don't use them. Try specifying the Jar with the main class explicitly in the class-path and see if the error message changes. – Andrew Thompson Jan 25 '12 at 11:58
  • The issue is there are hundreds of jar files. And I dont know which is needed and which is not. – Dilshan Jan 25 '12 at 12:01
  • 1
    One that is needed is the one containing the main class. Can you identify that one? Note that my suggestion was *not* intended as a final solution (which would be found through my point 1. that you seem to be ignoring), it was just intended as a debugging aid to confirm if the wildcards had any effect as used. – Andrew Thompson Jan 25 '12 at 12:06
  • I used the Main-Class and it was there when I test the above. Any other solution for this? As I heard java 6 and upwards it supports wildcards like this – Dilshan Jan 25 '12 at 12:10
  • What OS are you running on, and more specifically, what is the value of [`path.separator`](http://pscode.org/prop/?prop=path.separator&format=TSV)? – Andrew Thompson Jan 25 '12 at 12:18