I am using com.emc.object.s3. I am trying to list all the key in a S3 bucket, but when I call the listObjects method in S3Client, it raises the following error.
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath. - with linked exception: [java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory] javax.ws.rs.WebApplicationException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath. with linked exception: [java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory] at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:115) at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:634) ... Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath. with linked exception: [java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory] at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:232) at javax.xml.bind.ContextFinder.find(ContextFinder.java:375) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632) at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getStoredJAXBContext(AbstractJAXBProvider.java:196) at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getJAXBContext(AbstractJAXBProvider.java:188) at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getUnmarshaller(AbstractJAXBProvider.java:140) at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.getUnmarshaller(AbstractJAXBProvider.java:123) at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:111) ... 96 more Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory at org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader.loadClass(TomcatEmbeddedWebappClassLoader.java:72) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220) at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92) at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:230) ... 104 more
I tried to add jaxb to build.gradle, but it doesn't help.
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.0-b170127.1453'
implementation 'javax.activation:activation:1.1'
implementation 'javax.xml.bind:jaxb-api:2.3.0'
listing method
public void list() {
ListObjectsResult objectListing = s3client.listObjects(nBucket);//this line causing the error
for (S3Object objectSummary : objectListing.getObjects()) {
System.out.println(" - " + objectSummary.getKey() + " " +
"(size = " + objectSummary.getSize() + ")");
}
}
How can I fix the problem? Alternatively, any other methods to list all keys?
2条答案
按热度按时间62lalag41#
官方的AWS SDK for Java V2 S3Client可以在Sping Boot web项目中完美运行。使用AWS JavaS3Client,您可以避免所有这些依赖性问题。
6ss1mwsb2#
最好使用官方AWS SDK而不是第三方API。