I tried hello world example from here and I can’t see any output in my program (in console when using “java” command). Is it something wrong I do? The code of marshal function looks like this:
public void marshal() {
try {
JAXBElement<GreetingListType> gl =
of.createGreetings( grList );
JAXBContext jc = JAXBContext.newInstance( "hello" );
Marshaller m = jc.createMarshaller();
m.marshal( gl, System.out );
} catch( JAXBException jbe ){
// ...
}
}
I tried also tried to put output into a file like this:
public void marshal() {
try {
JAXBElement<GreetingListType> gl =
of.createGreetings( grList );
JAXBContext jc = JAXBContext.newInstance( "hello" );
FileOutputStream fos = new FileOutputStream("plik.xml");
Marshaller m = jc.createMarshaller();
//m.marshal( gl, System.out );
m.marshal(gl, fos);
fos.close();
} catch( JAXBException jbe ){
// ...
}
catch( IOException ioe ){
// ...
}
}
but it didn’t work out. Have you got any solutions?
EDIT: After printing Stack Trace it gave me this, looks promising:
javax.xml.bind.JAXBException: "hello" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:186)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:148)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:310)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:392)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:357)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:264)
at Hello.marshal(Hello.java:28)
at Hello.main(Hello.java:43)
I do have ObjectFactory but don’t know anything about jaxb.index. Is it necessary? How it should look like?
The demo appears to be incomplete (missing main method):
Below is the corrected version:
Output