java.net.MalformedURLException: no protocol

simran picture simran · Dec 29, 2010 · Viewed 68.5k times · Source

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?

Answer

Vladimir Ivanov picture Vladimir Ivanov · Dec 29, 2010

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