jaxb.properties missing at runtime when built with Maven(使用 Maven 构建时在运行时缺少 jaxb.properties)
问题描述
我有一个项目,我想使用一组由 JAXB 从 XSD 生成的类.有了这些类,我想从 XML 和 JSON 编组/解组.
I have a project where I want to work with a set of Classes generated by JAXB from an XSD. With these classes I would like to marshall/unmarshall from XML and JSON.
我发现我需要 Moxy Eclipselink 来做我需要的事情.我将我的类和流程作为一个 Ant 项目进行了测试,然后我决定将其移至 Maven 以进行更好的管理.
I've figured out I would need Moxy Eclipselink to do what I need. I tested my classes and process as an Ant project, then I decided to move it over to Maven for better management.
但是,在运行时似乎无法识别 jaxb.properties 文件.
However, the jaxb.properties file does not seem to be recognized at runtime.
我的项目有一个用于对象的 Maven 工件,以及另一个用于逻辑/处理的工件.我一直在努力找出将 jaxb.properties 放在哪里以便阅读.
My project has a Maven artifact for the objects, and another artifact for the logic/processing. I've been pulling my hair out trying to figure out where to put the jaxb.properties so it could be read.
我试过了
对象项目
/src/main/resources/jaxb.properties
/src/main/java/[namespace]/jaxb.properties
逻辑项目
/src/main/resources/jaxb.properties
/src/main/java/[namespace]/jaxb.properties
但是,当我尝试获取 JAXBContext 的类名时,我仍然得到:
However, when I try to get the classname of my JAXBContext I still get:
class com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
如果我通过指定以下 JVM 选项来修改运行设置:
If I modify my run settings by specifying a JVM option of:
-Djavax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
我明白了:
class org.eclipse.persistence.jaxb.JAXBContext
在这两个项目中,我都在 pom.xml 中指定了这一点
In both projects I have specified this in the pom.xml
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
如果我查看 JAR,我会在其中看到 jaxb.properties.
If I look at the JAR, I see jaxb.properties in there.
现在我很困惑.
推荐答案
您需要确保jaxb.properties 文件与对应的模型类在同一个包结构的resources 目录下.
You need to make sure the jaxb.properties file is under the resources directory in the same package structure as the corresponding model classes.
示例
- https://github.com/bdoughan/blog20110322
这篇关于使用 Maven 构建时在运行时缺少 jaxb.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Maven 构建时在运行时缺少 jaxb.properties
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
