'aspose email with java 11
I am trying to upgrade the aspose email version to 20.7 and I am using java 11 for my project, but I get these exceptions. The aspose email jar is in the classpath.
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.*
com.* nested exception is java.lang.NoClassDefFoundError: com/aspose/email/MailMessage
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 95 more
Caused by: java.lang.NoClassDefFoundError: com/aspose/email/MailMessage
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:382)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:320)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:798)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:493)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
... 97 more
Caused by: java.lang.ClassNotFoundException: com.aspose.email.MailMessage
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
... 113 more
Solution 1:[1]
If you plan to use EWSClient API with JDK11 or above, we need to add JAXB dependencies. All other Aspose.Email API works normally without any additional dependencies.
(The JAXB APIs are considered to be Java EE APIs, and therefore are no longer contained on the default class path in Java SE 9. In Java 11 they are completely removed from the JDK. Issue described on stackoverflow: How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9 1
Maven JAXB dependencies:
- javax.xml.bind jaxb-api 2.3.1
- com.sun.xml.bind jaxb-impl 2.3.1
- com.sun.xml.bind jaxb-core 2.3.0.1
- com.sun.xml.messaging.saaj saaj-impl 1.5.0
There has been similar question asked over following thread as well. https://forum.aspose.com/t/migrating-aspose-email-to-20-7-with-java-11/219092
Solution 2:[2]
The Dependency Management allows to consolidate and centralize the management of dependency versions without adding dependencies which are inherited by all children. This is especially useful when you have a set of projects (i.e. more than one) that inherits a common parent.
Another extremely important use case of dependencyManagement is the control of versions of artifacts used in transitive dependencies.
In the parent POM, the main difference between the dependencies and dependencyManagement is this:
Artifacts specified in the dependencies section will ALWAYS be included as a dependency of the child module(s).
Artifacts specified in the dependencyManagement section, will only be included in the child module if they were also specified in the dependencies section of the child module itself.
You specify the version and/or scope in the parent, and you can leave them out when specifying the dependencies in the child POM. This can help you use unified versions for dependencies for child modules, without specifying the version in each child module.
For example, PARENT POM dependencyManagement:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-email</artifactId>
<version>${lib.email.aspose.version}</version>
<classifier>jdk16</classifier>
</dependency>
</dependencies>
</dependencyManagement>
CHILD POM dependencies:
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-email</artifactId>
<classifier>jdk16</classifier>
</dependency>
</dependencies>
I suggest you to build test project with maven. I am sure that child module included Aspose.Email dependency in the dependencies section.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Wai Ha Lee |
Solution 2 | Mudassir |