Java.net.MalformedURLException: no protocol

I am writing a class to run xjc in java. my code is 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?

+4
source share
3 answers

Try adding "file://" to the top of your file path. But, as Bojo suggested, you don’t need a URL here.

+14
source

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

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

 new InputSource(new FileReader(path)) 
+9
source

I had higher by opening a virtual console.

Resolution. In the browser, you have chosen a very safe option.

Start β†’ Java Configuration β†’ Security --Classing Enabled - Very High.

-1
source

Source: https://habr.com/ru/post/1333722/


All Articles