How to know what JAXB implementation is used?

后端 未结 2 976
别跟我提以往
别跟我提以往 2020-12-31 10:46

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).

<
2条回答
  •  一个人的身影
    2020-12-31 11:14

    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");
            }
        }
    
    }
    

    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());
        }
    }
    

提交回复
热议问题