title: NoClassDefFoundError: javax/ws/rs/WebApplicationException
body: <p>I have the following class that uses JAX-RS to consume an api:</p>
  
  <pre><code>public class PackageProcessor implements IPackageProcessor {
  
      public PackageProcessor() {   
      }
  
      @Override
      public PackageDimensions getPackageDimensions(byte[] image) throws PackageProcessorException {
          Image imageBase64 = toBase64(image);
          PackageDimensions dimensions = null;
          try {
              Client client = ClientBuilder.newClient();
              dimensions = client.target(BASE_URI)
                      .path(DIMENSIONS_PATH)
                      .request(MediaType.APPLICATION_JSON)
                      .accept(MediaType.APPLICATION_JSON)
                      .post(Entity.json(imageBase64))
                      .readEntity(PackageDimensions.class);
  
          } catch (WebApplicationException ex) {
              throw new PackageProcessorException("Error al procesar la imagen", ex);
          }
  
          return dimensions;
      }
  
  }
  </code></pre>
  
  <p>I'm trying to use it in a Java Application just to test if it works:</p>
  
  <pre><code>public static void main(String[] args)  {
      try {
          IPackageProcessor p = new PackageProcessor();
  
          Path path = Paths.get("path");
          byte[] data = Files.readAllBytes(path);
          PackageDimensions d = p.getPackageDimensions(data);
  
      } catch (IOException ex) {
          Logger.getLogger(Prueba.class.getName()).log(Level.SEVERE, null, ex);
      } catch (PackageProcessorException ex) {
          Logger.getLogger(Prueba.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  </code></pre>
  
  <p>But when I try to run this application I get the following error in the line doing the <code>new PackageProcessor()</code>:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/WebApplicationException
      at prueba.Prueba.main(Prueba.java:25)
  Caused by: java.lang.ClassNotFoundException: javax.ws.rs.WebApplicationException
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 1 more
  </code></pre>
  
  <p>I understand what it means but I'm not calling anything that throws that in the constructor, am I?</p>
  
  <p>I don't want to have to add a dependecy to JAX-RS in my java application, and that's way I'm encapsulating a possible <code>WebApplicationException</code> inside my own exception class <code>PackageProcessorException</code>. I thought that would be enough.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>I'm using Netbeans, if that changes anything</p>
  
  <h2><strong>Update</strong></h2>
  
  <p>Thanks for the explanations which seem correct, but if that's the case there is no way my java application can ignore the implementation of the <code>PackageProcessor</code>? </p>
  
  <p>That was what I was hoping for.</p>