'Spring Boot, ClassNotDef Error with JaxB, Package -Info.java

I am using AJSC framework in SpringBoot with JaxB implementation. I built the stubs outside the project and copied them inside the project with proper directories.

However, during API execution, i get a classNotDef error. But I have seen my Jar file and i have the package-info class file inside the directory.

Caused by: java.lang.NoClassDefFoundError: BOOT-INF/classes/com/att/fpp/fpprome/opportunity/package-info (wrong name: com/att/fpp/fpprome/opportunity/package-info)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.hibernate.annotations.common.util.StandardClassLoaderDelegateImpl.classForName(StandardClassLoaderDelegateImpl.java:57)
    at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl$4.classForName(MetadataBuilderImpl.java:758)
    at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.packageForName(JavaReflectionManager.java:148)
    at org.hibernate.cfg.AnnotationBinder.bindPackage(AnnotationBinder.java:281)
    at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.prepare(AnnotationMetadataSourceProcessorImpl.java:186)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.prepare(MetadataBuildingProcess.java:156)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:253)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at acsi.grid.gridcore.core.sql.EntityManagerHelper.getDefaultEntityManager(EntityManagerHelper.java:250)
    at acsi.grid.gridcore.core.sql.EntityManagerHelper.getEntityManager(EntityManagerHelper.java:174)
    at acsi.grid.gridcore.core.JdbcGridBagImpl.getEntityManager(JdbcGridBagImpl.java:188)
    at acsi.grid.gridcore.core.JdbcGridBagImpl.put(JdbcGridBagImpl.java:163)
    at com.att.fpp.fpprome.dao.impl.OpportunityDaoImpl.updateOpportunityDatabaseROME(OpportunityDaoImpl.java:497)
    at com.att.fpp.fpprome.bo.impl.OpportunityBusinessObjectImpl.getOpptyInfo(OpportunityBusinessObjectImpl.java:78)
    at com.att.fpp.fpprome.service.impl.OpportunityServiceImpl.getOpportunitiesById(OpportunityServiceImpl.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)

Also I noticed that I am not using apache.cxf anywhere in pom but yet it is being called here.



Solution 1:[1]

Found the issue. The AJSC framework implementing the ADF (Hibernate based ORM) did not support package-info and hence searched for that class everytime.

Only way around was to execute the command to not generate the package-info during stubs generation.

Use -npa in XJC utility to suppress package-info and everything will work.

Solution 2:[2]

A possible solution for the NoClassDefFoundError originated by the package-info class: Spring boot, runnable jar can't load package-info.class

Solution 3:[3]

In case you got here by looking for a solution to a similar "package-info (wrong name:" issue, I fixed my problem by upgrading hibernate (since the one in the app was quite old).

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 Grim42
Solution 2 baronKarza
Solution 3 Mitch1077487