Is there a way to embed XML Schema in Java application so that it cannot be changed (only used by the application)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For your stated level of requirement it is sufficient to bundle your schema and code together in a JAR. Since the contents cannot be changed by the client (without intent) this fulfills your needs. Now, this doesn’t stop anyone from unpacking the archive and running the app manually, but really, you can’t prevent a determined hacker from doing what they will to your binary, once it’s out ‘in the wild’.
You didn’t mention how you are using the XML schema, but it is possible to validate marshall/unmarshall operations against a schema at run time, for most binding frameworks. Read this SO post for a general JAXB example:
How to validate against schema in JAXB 2.0 without marshalling?