0

I'm executing 3rd part JAR file, but need to add extra directory to Java classpath, so that the Java application I'm executing is able to find and load my own class.

It doesn't work when I do like the following

java -cp 'path/to/my/class' -jar /usr/local/Cellar/ThirdParty.jar custom-command MyClass -some-more-args

But works with the following

java -cp '/usr/local/Cellar/ThirdParty.jar:path/to/my/class' xxx.company.ThirdPartyMainClass custom-command MyClass -some-more-args

Is it so that when using -jar option class path are ignored? Or what's the difference?

Fedor
  • 1,392
  • 1
  • 17
  • 30

1 Answers1

0

As @dave_thompson_085 pointed out -classpath option doesn't take effect when -jar option is used. From documentation:

When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

Fedor
  • 1,392
  • 1
  • 17
  • 30