无法使用JAXB配置Moxy [英] Not able to configure Moxy using JAXB

查看:87
本文介绍了无法使用JAXB配置Moxy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码集中使用JAXB的Moxy实现,并尝试使用@XMLPath创建路径,但它似乎无法正常工作.我有一个Spring Bass项目,并且在/project/WEB/src/main/resources下创建了具有内容的jaxb.properties:

I am using Moxy Implementation of JAXB in my codeset and trying to create paths using @XMLPath but it seems to be not working. I have a Spring bassed Project and I have created jaxb.properties under /project/WEB/src/main/resources having content :

javax.xml.bind.context.factory = org.eclipse.persistence.jaxb.JAXBContextFactory

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

我的班级放在/project/WEB/src/main/java下 我已经配置了pom.xml以下载依赖项. persistence.moxy->

My classes are placed under /project/WEB/src/main/java I have configured my pom.xml to download the dependancy. persistence.moxy -->

<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.moxy</artifactId>
     <version>2.4.0</version>
</dependency>

当我在WAS服务器上运行代码时,未确认Moxy,也未创建路径.不知道我在做什么错.

When I run the code on WAS server, Moxy is not recongnized and the path is not created. Not sure what am I doing wrong.

我什至尝试测试我的JAXBContext类,但在控制台上看到的是:

I even tried testing my JAXBContext class but what I get on the console is :

JAXBContext jaxbContext = JAXBContext.newInstance(DocGenerator.class); 
System.out.println(jaxbContext.getClass());

com.sun.xml.bind.v2.runtime.JAXBContextImpl类

class com.sun.xml.bind.v2.runtime.JAXBContextImpl

有人可以帮忙吗?

推荐答案

如果这对其他人有帮助,以下内容解决了我最近的"MOXy已配置但被忽略"的问题.

In case this helps anyone else, the following fixed my recent "MOXy is configured but is being ignored" problem.

我通过实现

I tested it on Java 11 (Open JDK) by implementing the first example shown in the @XmlPath Javadoc.

根据说明此处,我添加了必需的属性文件添加到包含我的域类(我要序列化的带注释的bean)的包中.

In line with the instructions here, I added the required properties file to the package containing my domain classes (the annotated beans which I wanted to serialize).

我最初忘记做的步骤是:

The step I initially forgot to do was this:

我的IDE仅将已编译的.class文件复制到目标目录-不会复制其他任何文件(例如我的属性文件).

My IDE only copies compiled .class files to the target directory - it does not copy anything else (such as my properties file).

杜.

如何修复取决于您的IDE.对我来说,这是对我的项目的ant构建配置的简单更改.

How you fix that depends on your IDE. For me, it was a simple change to the ant build configuration for my project.

类似地,需要指示Maven将文件复制到JAR中的该文件夹.有多种方法可以做到这一点.请参阅此问题一些答案.

Similarly, Maven needs to be instructed to copy the file to that folder in your JAR. There are various ways to do this. See this question for some answers.

将此特定的配置文件放置到resources目录中不会 起作用(至少对我而言不起作用). MOXy指令非常具体-需要严格遵守.

Placing this specific config file into a resources directory does not work (at least, it did not work for me). The MOXy instructions are quite specific - and need to be followed exactly.

在Java 11中,模块java.se.ee已被删除.参见 JEP-320 .该模块包括JAXB(和JAX-WS).要在Java 11及更高版本中使用JAXB,您需要将其作为单独的库添加到项目中.

In Java 11, the module java.se.ee has been removed. See JEP-320. This module includes JAXB (and JAX-WS). To use JAXB in Java 11 and newer, you need to add it to your project as a separate library.

鉴于此,我的POM依赖项记录在案:

Given that, here are my POM dependencies, for the record:

        <dependency>
            <groupId>com.sun.activation</groupId>
            <artifactId>javax.activation</artifactId>
            <version>1.2.0</version>
        </dependency>

        <!-- 
             Use 2.3.1 below to prevent "illegal 
             reflective access operation" warnings.
        -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.3.0.1</version>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.7.6</version>
        </dependency>

这篇关于无法使用JAXB配置Moxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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