9

I' m writing a class to run xjc in java. my code goes as follows:

 URL url = new URL("C:\\Users\\Simran\\Desktop\\books.xsd"); 
 SchemaCompiler sc = XJC.createSchemaCompiler();
 sc.parseSchema(new InputSource(url.toExternalForm()));
 S2JJAXBModel model = sc.bind();
 JCodeModel cm = model.generateCode(null, null);
 cm.build(new FileCodeWriter(new File("C:\\Users\\Simran\\Desktop\\books.xsd")));

however I get the following error when I run this:

Exception in thread "main" java.net.MalformedURLException: no protocol: books.xsd
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at jaxbTest.Test1.main(Test1.java:22)

Can anyone help with this please?

2
  • Have you tried sc.parseSchema(new InputSource("C:\\Users\\Simran\\Desktop\\books.xsd")); As I suggested before ? Commented Dec 29, 2010 at 18:39
  • ya i had tried this & it didnt work Commented Dec 29, 2010 at 18:42

3 Answers 3

19

Try append "file://" to the beginning of your file path. But as Bozho proposed, you don't need an URL here.

Sign up to request clarification or add additional context in comments.

4 Comments

+1, mentioned the file:// protocol while I was adding it to my answer :)
can anyone give me some link for using xjc through API calls?
oh, please mark some answer as accepted and ask another question. Don't use comments for that.
but in ubuntu ?
11

This is not a valid URL. It can be made valid by prepending file:// as protocol.

But you don't need a URL at all. You can pass a Reader (as well as an InputStream) to the InputSource constructor. So for example:

new InputSource(new FileReader(path))

2 Comments

i always thought that it was with three /'s, like file:///, but am upvoting this answer. also the correct term is not appending but prepending.
thanks for the "prepending". It works with two slashes as well, I'm not sure which is the standard. I guess it gets normalized regardless of the number of slashes.
-4

I had the above ,while opening the virtual console.

Resolution : You have select very secure option in Browser.

Start--> Java configuration -->Security --Cilick on - Very High.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.