使用Maven构建时,运行时缺少jaxb.properties [英] jaxb.properties missing at runtime when built with Maven

查看:102
本文介绍了使用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

这篇关于使用Maven构建时,运行时缺少jaxb.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆