Manifest.mf and imports

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-16 05:50:33

问题


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.

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?

来源:https://stackoverflow.com/questions/60781244/manifest-mf-and-imports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!