如何知道使用了什么 JAXB 实现? [英] How to know what JAXB implementation is used?

查看:41
本文介绍了如何知道使用了什么 JAXB 实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MOXy 作为 JAXB 实现,但不知何故我想在某些管理屏幕上显示实现名称(例如 Moxy)和版本号(动态).

I am using MOXy as JAXB Implementation but somehow I would like to show the Implementation Name (e.g. Moxy) and the version number on some admin screen (dynamically).

如何从 JAXB 中检索该信息?

How can I retrieve that info from JAXB?

干杯

推荐答案

您可以执行以下类似操作来找出正在使用的 JAXB 实现:

You could do something like the following to figure out the JAXB impl being used:

import javax.xml.bind.JAXBContext;

public class Demo {

    private static final String MOXY_JAXB_CONTEXT = "org.eclipse.persistence.jaxb.JAXBContext";
    private static final String METRO_JAXB_CONTEXT = "com.sun.xml.bind.v2.runtime.JAXBContextImpl";

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Root.class);

        String jaxbContextImpl = jc.getClass().getName();
        if(MOXY_JAXB_CONTEXT.equals(jaxbContextImpl)) {
            System.out.println("EclipseLink MOXy");
        } else if(METRO_JAXB_CONTEXT.equals(jaxbContextImpl)) {
            System.out.println("Metro");
        } else {
            System.out.println("Other");
        }
    }

}

您可以从它的 Version 类中获取有关正在使用的 EclipseLink 版本的信息:

You can get information about the EclipseLink version being used from it's Version class:

import org.eclipse.persistence.Version;

public class VersionDemo {

    public static void main(String[] args) {
        System.out.println(Version.getVersion());
    }
}

这篇关于如何知道使用了什么 JAXB 实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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