Question

I have a situation where I need to use javax.xml library and majority of this comes from Java 6. However my deployment server runs on Java 5, where I don't have control.

So is it possible to add these specific libraries to project and can run in Java 5 environment?

I am mainly using

import javax.xml.bind.*;
import javax.xml.stream.*;
import javax.xml.transform.stream.StreamSource;

code which I am using

    XMLInputFactory xif = XMLInputFactory.newFactory();
    StreamSource xml = new StreamSource("input.xml");
    XMLStreamReader xsr = xif.createXMLStreamReader(xml);
    while(xsr.hasNext()) {
        if(xsr.isStartElement() && xsr.getLocalName().equals("StandardError")) {
            break;
        }
        xsr.next();
    }

So can any one tell how can I avoid this so that My application can run in Java 5 environment without issues.

Between we use maven for building, so any libraries has to go into pom.xml

Was it helpful?

Solution

JAXB (JSR-222) and StAX (JSR-173) were introduced in Java EE 5 and are completely compatible with Java SE 5 (The version of the JDK when those specs were released). Of course implementations of these standards were included as part of Java SE 6.

java.net Repository

You can obtain the public APIs for the standards from the java.net repository

    <repository>
        <id>java.net</id>
        <name>java.net Maven Repository</name>
        <url>https://maven-repository.dev.java.net/nonav/repository</url>
    </repository>

Below is the dependency for the latest version of the JAXB public APIs

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2</version>
    </dependency>

Implementations

In addition to the public APIs you will need to implementations. Each spec has multiple implementations. Below is a link to a POM file that pulls in EclipseLink MOXy as the JAXB implementation (Note: I'm the MOXy lead).

About Java SE 5

Java SE 5 hasn't received any public updates since October 2009, even Java SE 6 is rapidly approaching the end of life. If possible I would recommend using Java SE 7 (and Java SE 8 is currently in development).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top