How do I use JAXB with Netbeans?

I downloaded books.xsd and books.xml from http://java.sun.com/developer/technicalArticles/WebServices/jaxb.

Generated the classes using ./xjc.sh -p test.jaxb /Users/Me/Temp/books.xsd -d /Users/Me/Temp/work.
It generated BookCategoryType.java, BookType.java, Collection.java, ObjectFactory.java, inside /Users/Me/Temp/work/test/jaxb directory. Then I compile them: javac *.java, generating BookCategoryType.class, BookType$Authors.class, BookType$Promotion.class, BookType.class, Collection$Books.class, Collection.class, ObjectFactory.class, inside the same directory.

How do I reference these classes from Netbeans? I am writing:

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.security.Security;

           JAXBContext jc = JAXBContext.newInstance("test.jaxb");
           Unmarshaller u = jc.createUnmarshaller();

           Collection collection= (Collection) unmarshaller.unmarshal(new File( "books.xml"));
           
I am aware that Collection shold be test.jaxb.Collection. How can I do it? It just doesn't find it (it tries to import java.util.Collection, and that is not the case.

Thanks in advance          

cinglezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
you need to include /Users/Me/Temp/work/ in the projects build path
0
cinglezAuthor Commented:
Ok, I've done that. Now, what I need is to turn the contents of the XML file into an java object. Could someone provide me an example on how to do that? I've been trying to do:

           JAXBContext jc = JAXBContext.newInstance("test.jaxb");
           Unmarshaller u = jc.createUnmarshaller();
           Object o = u.unmarshal(new File ("books.xml"));

But when I run the executable (java -jar Teste.jar, I always get

javax.xml.bind.JAXBException: "test.jaxb" 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:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
      at javax.xml.bind.ContextFinder.find(ContextFinder.java:290)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
      at Teste.Status.listaStatus(Status.java:41)
      at Teste.Status.main(Status.java:73)

Any ideas?

Thanks
0
objectsCommented:
are the classes and jaxb.properties included in the jar?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

cinglezAuthor Commented:
Yes they were. I will close this thread, because I solved my problems using Apache Axis instead of JAXB directly.

Thanks anyway
0
objectsCommented:
I already answered the original question
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cinglezAuthor Commented:
Ok, I agree
0
objectsCommented:
thanks mate
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.