gpt4 book ai didi

javax.xml.bind.JAXBException Hibernate Java 10

转载 作者:太空宇宙 更新时间:2023-11-04 10:04:53 32 4
gpt4 key购买 nike

我正在尝试将我的 Hibernate Gradle 项目更新到 Java 10。我收到以下错误:

Caused by: org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null
at org.hibernate.orm.core@5.3.6.Final/org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
at org.hibernate.orm.core@5.3.6.Final/org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.orm.core@5.3.6.Final/org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.orm.core@5.3.6.Final/org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165)
at org.hibernate.orm.core@5.3.6.Final/org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at org.hibernate.orm.core@5.3.6.Final/org.hibernate.cfg.Configuration.configure(Configuration.java:244)
at com.kiryltkach.bettingtools.betstore.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:14)
... 75 more
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:278)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:409)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
at org.hibernate.orm.core@5.3.6.Final/org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:122)
... 81 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
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)
... 85 more

我仔细看了this answer ,这是我的 build.gradle 文件:

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'com.project.example.Main'

repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.6.0'
}
}

apply plugin: 'com.google.osdetector'

ext.platform = osdetector.os == 'osx' ? 'mac' : osdetector.os == 'windows' ? 'win' : osdetector.os

compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
}

run {
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls',
//'--add-modules', 'java.xml.bind',
//'--add-modules', 'java.se.ee',
'--add-exports', 'javafx.graphics/com.sun.javafx.util=ALL-UNNAMED',
'--add-exports', 'javafx.base/com.sun.javafx.reflect=ALL-UNNAMED',
'--add-exports', 'javafx.base/com.sun.javafx.beans=ALL-UNNAMED'
//--add-exports=javafx.graphics/com.sun.glass.utils=ALL-UNNAMED
//--add-exports=javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
]
}
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
compile 'org.hibernate:hibernate-core:5.3.6.Final'
compile group: 'postgresql', name: 'postgresql', version: '9.4.1208-jdbc42-atlassian-hosted'
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.1'
compile group: 'org.jsoup', name: 'jsoup', version: '1.11.3'
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
compile group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0.1'
compile group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.1'
compile group: 'javax.activation', name: 'activation', version: '1.1.1'

compile "org.openjfx:javafx-base:11:$platform"
compile "org.openjfx:javafx-graphics:11:$platform"
compile "org.openjfx:javafx-controls:11:$platform"
compile "org.openjfx:javafx-fxml:11:$platform"
compile "org.openjfx:javafx-web:11:$platform"
}

如您所见,我已添加 javax.xml.bind 作为依赖项,但似乎 hibernate 仍然忽略它。但是,如果我尝试添加 jvm 参数 '--add-modules', 'java.xml.bind',我会得到 java.lang.module.ResolutionException: Modules activate and java.activation export package javax.activation to module org.jsoup。那么,如何解决这个问题呢?

编辑:IDE(在我的例子中是 eclipse)知道 com.sun.xml.bind.v2.ContextFactory 类(自动完成功能正在处理此类)。

最佳答案

尝试添加此依赖项:

compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'

它应该可以工作。

关于javax.xml.bind.JAXBException Hibernate Java 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53056987/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com