You can set the Schema directly in the Marshaller. First, you need to create a Schema instance (javax.xml.validation package):
SchemaFactory factory = SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new StreamSource(new File("schema1.xsd")));
Now that you have the Schema, just set the property in the Marshaller to
validate the generated XML:
MovieLibrary library = ...; // <-- your JAXB-annotated tree
JAXBContext ctx = JAXBContext.newInstance(MovieLibrary.class);
Marshaller marshaller = ctx.createMarshaller();
marshaller.setSchema(schema);
marshaller.marshal(new JAXBElement<MovieLibrary>(new QName("movieLibrary"),
MovieLibrary.class, library),
new FileOutputStream("/tmp/library.xml"));
See also "How to Validate Input against an XML Schema?" in the Jarfiller JAXB Guide.