问题
I have the following dynamodb.jar
structure, where lib/
has a bunch of .jar
s. All these nested .jar
s 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 import
ed by com.mparnisa.dynamodb.table.CreateHandler
.
My questions:
- Do I need to change anything in MANIFEST.MF so that the
import
is resolved properly? - Is
URLClassLoader
smart enough to look into the MANIFEST.MF for theclass-path
?
来源:https://stackoverflow.com/questions/60781244/manifest-mf-and-imports