- Saved searches
- Use saved searches to filter your results more quickly
- java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener for JAXB v2.2.11 #15
- java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener for JAXB v2.2.11 #15
- Comments
- Решение ошибки java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
- [Solved] java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
- About the Author:
- Add comment
- Comments
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener for JAXB v2.2.11 #15
java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener for JAXB v2.2.11 #15
Comments
apply plugin: 'com.github.jacobono.jaxb' dependencies < jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.11' jaxb 'com.sun.xml.bind:jaxb-impl:2.2.11' jaxb 'javax.xml.bind:jaxb-api:2.2.11' >10:07:01.752 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class org.xml.sax.ErrorHandler loaded from parent loader (parentFirst) 10:07:01.762 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Resource com/sun/tools/xjc/api/ErrorListener.class loaded from ant loader 10:07:01.782 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Couldn't load Resource com/sun/xml/bind/api/ErrorListener.class 10:07:01.792 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':iqpdct-iodd101:xjc' 10:07:01.802 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :iqpdct-iodd101:xjc FAILED 10:07:01.822 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :iqpdct-iodd101:xjc (Thread[main,5,main]) completed. Took 1.972 secs. 10:07:01.832 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 3.137 secs, idle: 0.038 secs 10:07:01.842 [ERROR] [org.gradle.BuildExceptionReporter] 10:07:01.852 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception. 10:07:01.862 [ERROR] [org.gradle.BuildExceptionReporter] 10:07:01.872 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong: 10:07:01.882 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':iqpdct-iodd101:xjc'. 10:07:01.892 [ERROR] [org.gradle.BuildExceptionReporter] > java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener 10:07:01.902 [ERROR] [org.gradle.BuildExceptionReporter] 10:07:01.912 [ERROR] [org.gradle.BuildExceptionReporter] * Try: 10:07:01.922 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. 10:07:01.942 [LIFECYCLE] [org.gradle.BuildResultLogger] 10:07:01.942 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
The text was updated successfully, but these errors were encountered:
I’m pretty sure this isn’t an error with the plugin. The class that isn’t
found is from the sun release of jaxb.
You need to either include another jar with that package or try a different
version of ant.
On Oct 30, 2014 9:19 AM, «Dmitry Ulanov» notifications@github.com wrote:
Gradle 2.1
Build time: 2014-09-08 10:40:39 UTC
Build number: none
Revision: e6cf70745ac11fa943e19294d19a2c527a669a53Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_25 (Oracle Corporation 25.25-b02)
OS: Windows 7 6.1 x86—
Reply to this email directly or view it on GitHub
#15 (comment)
.
Hm, ‘com/sun/xml/bind/api/ErrorListener’ was in ‘jaxb-impl’ in 2.2.7, but was removed in 2.2.11.
I’m not sure if they removed it entirely out of 2..2.11 or if it is in
another jar release.
On Oct 30, 2014 9:24 AM, «Dmitry Ulanov» notifications@github.com wrote:
Hm, ‘com/sun/xml/bind/api/ErrorListener’ was in ‘jaxb-api’ in 2.2.7, but
was removed in 2.2.11.—
Reply to this email directly or view it on GitHub
#15 (comment)
.
So, broken maven dependecy ‘jaxb-xjc’ ‘jaxb-core’ for 2.2.11
I was just looking in their repository and I saw that error listener is
still there.
Thanks for finding the package! I was about to go digging.
This also looks new, and encompasses all the jars you probably need for 2.2.11.
You might be able to go from this
dependencies < jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.11' jaxb 'com.sun.xml.bind:jaxb-impl:2.2.11' jaxb 'javax.xml.bind:jaxb-api:2.2.11' >
dependencies < jaxb 'com.sun.xml.bind:jaxb-ri:2.2.11' >
no, jaxb-ri has ‘pom’ and not working, but this variant is ok:
apply plugin: 'com.github.jacobono.jaxb' dependencies
Thanks a lot, i am closing this issue, but this is a error in ‘jaxb-xjc’ pom.
Thanks a million for this.
Hey, I am refereeing to the same error from http://stackoverflow.com/questions/30084367/spring-oauth2-wso2-integration-example . for that I added following dependency
But still I see following error comming. Could you please guide me ASAP? As I am unable to resolved this error from last 3+ weeks.
Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate: com/sun/xml/bind/ api/ErrorListener —————————————————— realm = plugin>org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3 strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy urls[0] = file:/C:/Users/prateek/.m2/repository/org/ jvnet/jaxb2/maven2/maven-jaxb2-plugin/0.12.3/maven-jaxb2-plugin-0.12.3.jar urls[1] = file:/C:/Users/ prateek/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin-core/0.12.3/maven-jaxb2-plugin- core-0.12.3.jar urls[2] = file:/C:/Users/prateek/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar urls[3] = file:/C:/Users/prateek/.m2/repository/org/apache/commons/commons-lang3/3.2.1/commons- lang3-3.2.1.jar urls[4] = file:/C:/Users/prateek/.m2/repository/com/sun/org/apache/xml/internal/resolver/ 20050927/resolver-20050927.jar urls[5] = file:/C:/Users/prateek/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar urls[6] = file:/C:/Users/prateek/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar urls[7] = file:/C:/Users/prateek/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb22-plugin/0.12.3/maven- jaxb22-plugin-0.12.3.jar urls[8] = file:/C:/Users/prateek/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/ jaxb-runtime-2.2.11.jar urls[9] = file:/C:/Users/prateek/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb- xjc-2.2.11.jar urls[10] = file:/C:/Users/prateek/.m2/repository/org/apache/maven/plugin-tools/maven-plugin- annotations/3.2/maven-plugin-annotations-3.2.jar Number of foreign imports: 5 import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]] import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]] import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]] import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]] import: Entry[import from realm ClassRealm[maven.api, parent: null]] —————————————————— (org.jvnet.jaxb2.maven2:maven-jaxb2-plugin: 0.12.3:generate:default:generate-sources)
A «better» solution would be to use the correct new dependencies of jaxb:
When using those 2 dependencies only, and removing all the legacy ‘com.sun.xml.bind’ dependencies, the above problem will be fixed.
To avoid confusion, it would be better to specify those dependencies in the README file.
Решение ошибки java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
Часто разработчики сталкиваются с ситуацией, когда их код, использующий классы JAXB API, которые были предоставлены как часть JDK в Java 6/7/8, при запуске на Java 9 вызывает ошибки. Это происходит из-за того, что указанные классы не могут быть найдены.
Примером такого кода может быть следующий фрагмент:
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; public class Main < public static void main(String[] args) < try < JAXBContext jaxbContext = JAXBContext.newInstance(Object.class); >catch (JAXBException e) < e.printStackTrace(); >> >
При запуске данного кода с JDK 9 и выше произойдет ошибка java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException .
Причина такого поведения заключается в том, что начиная с Java 9, некоторые модули, включая JAXB, были удалены из JDK. Это было сделано в целях уменьшения размера JDK и JRE.
Для решения этой проблемы, можно использовать один из следующих подходов:
- Добавление нужных модулей в runtime с использованием флага —add-modules . В этом случае в командной строке для запуска программы будет выглядеть следующим образом: java —add-modules java.xml.bind Main .
- Использование зависимостей JAXB из Maven. Для этого в файл pom.xml необходимо добавить следующую зависимость:
<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.1</version> </dependency>
После этого классы JAXB будут доступны для использования, так как они будут загружены из зависимостей Maven.
Оба этих подхода позволят избежать ошибки java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException при запуске программы на JDK 9 и выше.
[Solved] java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
In Java web application development, you may encounter the following error when starting the server (e.g. Apache Tomcat):
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException . . Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException . . .
It is because the JAXB library (Java Architecture for XML Binding) is missing in the classpath. JAXB is included in Java SE 10 or older, but it is removed from Java SE from Java 11 or newer –moved to Java EE under Jakarta EE project.
That means if you encounter JAXBException error, it’s very much likely that you are using Java 11 or newer for your project – or at least the server is running under on that Java version. So to fix this error, you have to options:
1. Use older Java version like JDK 8, 9 or 10 which still include the JAXB library by default. Or:
2. Specify an additional dependency in your project’s pom.xml file as follows:
In case you don’t use Maven, you can manually download the JAXB JAR file from Maven repository, and add it to the project’s classpath:
That’s the solution to fix the error java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException .
About the Author:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.
Add comment
Comments
To Orlando Reyes: Try clean and rebuild the project, also update Maven project if you Eclipse; or refresh Maven if you use IntelliJ.
I have already added the javax.xml.bind dependency as you suggest and the error java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException persists.
To KJ: Convert your project to use Maven to take its advantages of dependency management so you will get rid of such issue. Reference: www.youtube.com/watch?v=kpJLWugEseY
I downloaded the JAR file and placed in a path in linux machine, added then path to the Linux CLASSPATH variable but still unable to compile. Please share your idea.
CodeJava.net shares Java tutorials, code examples and sample projects for programmers at all levels.
CodeJava.net is created and managed by Nam Ha Minh — a passionate programmer.
Copyright © 2012 — 2023 CodeJava.net, all rights reserved.