title: org.apache.sling.api.scripting.ScriptEvaluationException: javax.servlet.ServletException: java.lang.NoClassDefFoundError
body: <p>The following exception is throwing on my cq pages, when I have the following code in a service class inside osgi bundle.  <strong>Any ideas ??</strong></p>
  
  <blockquote>
    <p>org.apache.sling.api.scripting.ScriptEvaluationException: javax.servlet.ServletException: java.lang.NoClassDefFoundError</p>
  </blockquote>
  
  <p><strong>service.getFund() will be called from JSP using Sling.getService() api</strong></p>
  
  <pre><code>@Component
  @Service(ProductService.class)
  public class ProductServiceImpl implements ProductService {
  
      public Fund getFund() {
  
          Product[] origList = resultProducts();  
          Product dumP = copyCustom(origList[0]);
          List&lt;Product&gt; pp = new ArrayList&lt;Product&gt;();
          pp.addAll(new ArrayList&lt;Product&gt;(Arrays.asList(origList)));
          pp.add(dumP);
          filteredProducts = (Product[])pp.toArray();
      }
  
      @SuppressWarnings("unchecked")
      private &lt;T&gt; T copyCustom(T entity) throws IllegalAccessException,  InstantiationException {
  
          Class&lt;?&gt; clazz = entity.getClass();
          T newEntity = (T) entity.getClass().newInstance();
  
          while (clazz != null) {
              copyFields(entity, newEntity, clazz);
              clazz = clazz.getSuperclass();
          }
          return newEntity;
      }
  
      private &lt;T&gt; T copyFields(T entity, T newEntity, Class&lt;?&gt; clazz) throws   IllegalAccessException {
          List&lt;Field&gt; fields = new ArrayList&lt;&gt;();
          for (Field field : clazz.getDeclaredFields()) {
              fields.add(field);
          }
  
          for (Field field : fields) {
              field.setAccessible(true);
              field.set(newEntity, field.get(entity));
          }
  
        return newEntity;
      }
  
  }
  </code></pre>