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

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

示例

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

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