使用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.
现在我很困惑。
Now I'm confused.
您需要确保 jaxb.properties
文件位于资源下与相应模型类相同的包结构中的目录。
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