title: Bouncy Castle not found in classpath, but works when run in maven
body: <p>This is a very weird error, that I don't know more about how to fix it.</p>
  <p>I'm using <a href="https://www.bouncycastle.org/" rel="nofollow noreferrer">Bouncy Castle</a> libs to decrypt a password. I configured it in my maven pom.xml as:</p>
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.bouncycastle&lt;/groupId&gt;
    &lt;artifactId&gt;bcprov-jdk15&lt;/artifactId&gt;
    &lt;version&gt;1.46&lt;/version&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>The <em>provided</em> scope is because it is a signed jar. It is a command-line application and I use maven-assembly-plugin to generate a jar with all the dependencies included. I can't include it because, as a signed jar, it would break the signature verification. Marking it as <em>provided</em> it isn't included in the generated jar.</p>
  <p>So I try to pass it in the classpath with the command:</p>
  <pre><code>java -cp bcprov-jdk15-1.46.jar -jar my_executable.jar 
  </code></pre>
  <p>but when I run, I get a Class not found exception:</p>
  <pre><code>java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
  </code></pre>
  <p>I've tried dozens of ways to run it, but always get the same error.</p>
  <p>But what is really weird is that my unit tests that use the library run fine. If I type <code>mvn test</code>, the exact code that fails when I run from the command-line works fine. If I go to my <code>~/.m2</code> repo and rename the <code>bcprov-jdk15-1.46.jar</code>, the tests fail with the same Class Not Found Error.</p>
  <p>Why my code can run from inside maven, but fails from a jar with dependencies file? I'm really lost.</p>