Problem with JAXBContext.newInstance

Oliver Z. oliver.zemann at gmail.com
Tue Feb 12 00:03:29 UTC 2019


Thanks for the documentation link. It says, JPMS is supported when jaxb 
2.4.0 comes out. So in that case, this is simply not yet supported, is 
this correct? For the moment, i can remove the module-info.java, then it 
works - at least for the moment as workaround, until 2.4.0 is released.

I believe, the example below only works because it has no module-info.java


> Using the JAX-B standalone,https://github.com/eclipse-ee4j/jaxb-ri, 
> seems a bit harder than it probably should be given where we are.
>
> The following command line  with the jars on the classpath:
> ——————
> java -cp 
> classes/:jars/jaxb-api-2.4.0.jar:jars/jaxb-runtime-2.4.0.jar:jars/jaxb-impl-2.4.0.jar:jars/istack-commons-runtime-3.0.7.jar:jars/javax.activation-api-1.2.0.jar 
> JAXBExample
> —————————
>
> will work with the following trivial example:
>
> ———————
> import javax.xml.bind.annotation.XmlAttribute;
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
>
> @XmlRootElement
> public class Customer {
>
>     String name;
>     int age;
>     int id;
>
>     public String getName() {
>         return name;
>     }
>
>     @XmlElement
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public int getAge() {
>         return age;
>     }
>
>     @XmlElement
>     public void setAge(int age) {
>         this.age = age;
>     }
>
>     public int getId() {
>         return id;
>     }
>
>     @XmlAttribute
>     public void setId(int id) {
>         this.id = id;
>     }
>
> }
>
> import java.io.File;
> import javax.xml.bind.JAXBContext;
> import javax.xml.bind.JAXBException;
> import javax.xml.bind.Marshaller;
>
> public class JAXBExample {
>     public static void main(String[] args) {
>
>         Customer customer = new Customer();
>         customer.setId(100);
> customer.setName("Lance Andersen");
>         customer.setAge(29);
>
>         try {
>
>             File file = new File("Customer.xml");
>             JAXBContext jaxbContext = 
> JAXBContext.newInstance(Customer.class);
>             Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
>
>             // output pretty printed
> jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
>
> jaxbMarshaller.marshal(customer, file);
> jaxbMarshaller.marshal(customer, System.out);
>
>         } catch (JAXBException e) {
> e.printStackTrace();
>         }
>
>     }
> }
> ——————————
>
> The JAX-B 2.4 documentation could be a bit more helpful 
> https://javaee.github.io/jaxb-v2/doc/user-guide/release-documentation.html#deployment-jaxb-on-jpms :-(
>
>
> HTH
>
> Lance
> <http://oracle.com/us/design/oracle-email-sig-198324.gif>
> <http://oracle.com/us/design/oracle-email-sig-198324.gif><http://oracle.com/us/design/oracle-email-sig-198324.gif>
> <http://oracle.com/us/design/oracle-email-sig-198324.gif>Lance 
> Andersen| Principal Member of Technical Staff | +1.781.442.2037
> Oracle Java Engineering
> 1 Network Drive
> Burlington, MA 01803
> Lance.Andersen at oracle.com <mailto:Lance.Andersen at oracle.com>
>
>
>


More information about the jigsaw-dev mailing list