1

I have the following dynamodb.jar structure, where lib/ has a bunch of .jars. All these nested .jars are needed by com.mparnisa.dynamodb.table.

enter image description here

From another IntelliJ project I am trying to instantiate a class within this dynamodb.jar:

try {
    File file  = new File("<path>/dynamo.jar");

    URL url = file.toURI().toURL();
    URL[] urls = new URL[]{url};

    ClassLoader urlClassLoader = new URLClassLoader(urls);

    String resourceModelClassName = "com.mparnisa.dynamodb.table.ResourceModel";

    Class<?> resourceModelClass = urlClassLoader.loadClass(resourceModelClassName);
    Object resourceModel = resourceModelClass.newInstance(); // this works

    String resourceHandlerClassName = "com.mparnisa.dynamodb.table.CreateHandler";

    Class<?> resHandlerClazz  = urlClassLoader.loadClass(resourceHandlerClassName);
    try {
        Object resourceHandlerInstance = resHandlerClazz.newInstance();

    } catch (NoClassDefFoundError e) {
        System.out.println(e.getMessage());
    }
} catch (Exception e){
    System.out.println(e.getMessage());
}

The code breaks with

java.lang.NoClassDefFoundError: com/amazonaws/AmazonServiceException

This class is within one of the nested JARs and is imported by com.mparnisa.dynamodb.table.CreateHandler.

My questions:

  1. Do I need to change anything in MANIFEST.MF so that the import is resolved properly?
  2. Is URLClassLoader smart enough to look into the MANIFEST.MF for the class-path?
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130

0 Answers0