java.net.MalformedURLException: no protocol
69,974
Solution 1
Try append "file://"
to the beginning of your file path. But as Bozho proposed, you don't need an URL here.
Solution 2
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))
Author by
simran
Updated on August 18, 2022Comments
-
simran over 1 year
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?
-
Bozho over 13 years+1, mentioned the
file://
protocol while I was adding it to my answer :) -
simran over 13 yearscan anyone give me some link for using xjc through API calls?
-
Kinjal Dixit over 13 yearsi always thought that it was with three /'s, like file:///, but am upvoting this answer. also the correct term is not appending but prepending.
-
Vladimir Ivanov over 13 yearsoh, please mark some answer as accepted and ask another question. Don't use comments for that.
-
Bozho over 13 yearsthanks 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.
-
nimour pristou about 7 yearsbut in ubuntu ?