JAXB-API has not been found on module path or classpath - java

How could I solve this?
I'm trying some Java code from a textbook (my first ever JAXB practice) in Eclipse.
I get the following error at runtime:
Exception in thread "main" 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.internal.bind.v2.ContextFactory] at
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278) at
javax.xml.bind.ContextFinder.find(ContextFinder.java:421) at
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721) at
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662) at
clasesjaxb.Ejemplo1_JAXB.main(Ejemplo1_JAXB.java:31) Caused by:
java.lang.ClassNotFoundException:
com.sun.xml.internal.bind.v2.ContextFactory at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at
javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
at
javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276)
... 4 more
I needed to add the jaxb-api-2.3.1.jar to the project classpath in order to the project classes to compile:
enter image description here

It seems that error was solved following "Specifying the EclipseLink MOXy Runtime" instructions at https://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/TheBasics
adding eclipselink.jar to the project classpath
adding a jaxb.properties file at the package location with this content: "javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory"

Related

How do I fix NoClassDefFoundError, the class path in the error is incorrect, but it's not in code I've written

EDIT: Just realised it's caused by a ClassNotFoundException, would still like some help.
I'm trying to update keycloak from version 12.0.3 to version 13.0.0, however when I make that change I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/jsontype/PolymorphicTypeValidator
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructors(Class.java:1651)
at org.jboss.resteasy.util.PickConstructor.pickSingletonConstructor(PickConstructor.java:30)
at org.jboss.resteasy.spi.ResteasyProviderFactory.createConstructorInjector(ResteasyProviderFactory.java:2821)
at org.jboss.resteasy.spi.ResteasyProviderFactory.createProviderInstance(ResteasyProviderFactory.java:2813)
at org.jboss.resteasy.spi.ResteasyProviderFactory.addMessageBodyReader(ResteasyProviderFactory.java:1048)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1821)
at org.jboss.resteasy.spi.ResteasyProviderFactory.register(ResteasyProviderFactory.java:3026)
at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.register(ResteasyClientBuilder.java:559)
at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.register(ResteasyClientBuilder.java:48)
at org.keycloak.admin.client.Keycloak.newRestEasyClient(Keycloak.java:71)
at org.keycloak.admin.client.Keycloak.<init>(Keycloak.java:53)
at org.keycloak.admin.client.KeycloakBuilder.build(KeycloakBuilder.java:147)
at socsan.myapp.v1.mymodule.keycloak.KeycloakUserManager.createKeycloakInstance(KeycloakUserManager.java:187)
at socsan.myapp.v1.mymodule.keycloak.KeycloakUserManager.<init>(KeycloakUserManager.java:36)
at socsan.myapp.v1.mymodule.mymodule.startServices(mymodule.java:51)
at socsan.myapp.common.lifecycle.ProcessStarter.runStartupTasks(ProcessStarter.java:61)
at socsan.myapp.common.lifecycle.ProcessStarter.start(ProcessStarter.java:48)
at socsan.myapp.v1.mymodule.mymodule.main(mymodule.java:34)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 20 more
I tried updating the fasterxml databind package too, but it didn't make any difference.
I noticed that the path to the correct jar in the maven repository is different to the path in the error.
In the maven repository there are stored at com/fasterxml/jackson/core/databind.
Does that have any baring on the issue?
How can I fix this?
EDIT 2:
In the parent pom we have this:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.8</version>
</dependency>
The only change made to the module pom was to increase the version as stated above.
looking at the dependency analyser for jackson-databind it does look a bit of a mess, I should also point out that we're using the maven shade plugin:

FeignBuilder ClassNotFoundException issue

I'm getting following exception in a project using OpenFeign. Please suggest how to resolve this issue.
Exception is given below:
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.seamless.ers.links.kyc.client.CustomerDetailsClient': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.openfeign.FeignClientFactoryBean] from ClassLoader [sun.misc.Launcher$AppClassLoader#18b4aac2]
at
...
Caused by: java.lang.ClassNotFoundException: feign.Feign$Builder
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_301]
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_301]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_301]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_301]
... 25 common frames omitted
Below are the dependencies added:
spring-cloud-starter
spring-cloud-openfeign-core
spring-boot-starter-test
spring-boot-starter-web
Most famous class loading exception and indicates that compiler have difficulties to detect proper dependent class i.e provided the dependency at runtime, following are most healer to issue
Check the version and probably duplication of your maven artifact for spring-cloud-starter - spring-cloud-openfeign-core if you are not using spring boot parent and if the artifacts imported properly from firtplace,
Check the scope of the dependencies, for the current case in hand the will be provided to compile <scope>provided</scope>
Exclude the duplicate dependencies that they provide spring feign as transparent dependency .

Gradle not including one dependency when creating the artifact

I am using Gradle in an IntelliJ project to manage dependencies in a Spring project to provide REST web services. As long as I run the project in the IDE it works fine, but if I execute the java -jar artifact.jar command it cannot start. The following error is printed
13:42:47.338 [main] WARN org.springframework.boot.SpringApplication - Unable to close ApplicationContext
java.lang.IllegalStateException: Failed to introspect Class [com.(...).web_services.JmsConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#2cdf8d8a]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358)
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:747)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:746)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:685)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:656)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1670)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:667)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:659)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1300)
at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:914)
at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:902)
at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:889)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:830)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:349)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
at com.(...).web_services.WebServicesApplication.main(WebServicesApplication.java:10)
Caused by: java.lang.NoClassDefFoundError: javax/jms/ConnectionFactory
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.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.jms.ConnectionFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 25 common frames omitted
I suppose the javax.jms.ConnectionFactory class comes with the Spring ActiveMQ package, and I already tried to update Gradle manually but that did not solve the problem. Also importing javax.jms.ConnectionFactory in the JMS class did not help. Any clue?
The first attempt was to create a fat jar using the following custom gradle task (as suggested by #MatteoNNZ following this guide).
task customFatJar(type: Jar) {
manifest {
attributes 'Main-Class': '<myPackage>.<myMainClass>'
}
baseName = 'all-in-one-jar'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
However, as this didn't work, I ran the predefined gradle task buildDependents that created a working .jar in the build/libs folder.

ObjectBox Java sometimes throws error java.lang.ClassNotFoundException: kotlin.text.Charsets

Sometimes when i run the application that using ObjectBox java with no kotlin coding, java throws this error. java.lang.ClassNotFoundException: kotlin.text.Charsets
dependencies {
// Optional: include all native libraries for distribution
implementation "io.objectbox:objectbox-linux:$objectboxVersion"
implementation "io.objectbox:objectbox-macos:$objectboxVersion"
implementation "io.objectbox:objectbox-windows:$objectboxVersion"
}
apply plugin: 'io.objectbox'
But run again the error gone and the application started normally... anything wrong? do i need to include kotlin lib in my gradle build manually? or its caused by the ide is building the project so get error on the first run its confusing here. I am using IntelliJ, Gradle,ObjectBox 2.8.1,Java 1.8
Stacktrace:
Exception in thread "Thread-109" java.lang.NoClassDefFoundError: kotlin/text/Charsets
at io.objectbox.reporting.BasicBuildTracker.sendEvent(BasicBuildTracker.kt:166)
at io.objectbox.reporting.BasicBuildTracker$sendEventAsync$1.run(BasicBuildTracker.kt:143)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: kotlin.text.Charsets
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
Caused by: java.lang.ClassNotFoundException: kotlin.text.Charsets
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
java.lang.ClassNotFoundException: kotlin.text.Charsets
Caused by: java.lang.ClassNotFoundException: kotlin.text.Charsets

Grails not picking patched jar file

I am working on grails 2.0.3 project. On the way I noticed that following dependency of grails 2.0.3: org.grails:grails-datastore-core:1.1.4.RELEASE had a bug. So I patched the jar file and placed it in lib folder of grails. In BuildConfig.groovy excluded grails jar file and gave my own dependency as given below
inherits("global") {
excludes "grails-datastore-core"
}
dependencies {
compile 'org.grails:grails-datastore-core:1.1.4.RELEASE'
}
Then ran following steps:
grails clean
grails compile --refresh-dependencies
grails run-app
but got following error:
2013-06-05 16:39:14,613 20831 ERROR [org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager] (pool-7-thread-1:) Error configuring dynamic methods for plugin [domainClass:2.0.3]: java.lang.NoClassDefFoundError: org/grails/datastore/mapping/core/SoftThreadLocalMap
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: org/grails/datastore/mapping/core/SoftThreadLocalMap
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NoClassDefFoundError: org/grails/datastore/mapping/core/SoftThreadLocalMap
at org.grails.datastore.mapping.core.AbstractDatastore.<clinit>(AbstractDatastore.java:46)
at java.lang.Class.forName(Class.java:171)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.grails.datastore.mapping.core.SoftThreadLocalMap
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 7 more
2013-06-05 16:39:14,714 20932 ERROR [org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager] (pool-7-thread-1:) Error configuring dynamic methods for plugin [hibernate:2.0.3]: java.lang.NoClassDefFoundError: org.grails.datastore.mapping.core.AbstractDatastore
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: org.grails.datastore.mapping.core.AbstractDatastore
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NoClassDefFoundError: org.grails.datastore.mapping.core.AbstractDatastore
at java.lang.Class.forName(Class.java:171)
... 5 more
I have tried renaming the jar file and changing scope of dependency to runtime but no luck.
I have also tried upgrading using this link but still get the same error.
Any kind of help is appreciated

Categories