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
Answers
USe AWS SDK for Java v2 S3Client. The official AWS SDK for Java V2 S3Client works perfectly in a Spring BOOT web project. Using the AWS Java S3Client, you can avoid all of these dependency issues.
It’s always better to use an official AWS SDK instead of 3rd party APIs.