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

查看:170
本文介绍了如何知道使用什么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 impl:

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天全站免登陆