java.net.MalformedURLException: no protocol

女生的网名这么多〃 提交于 2019-12-23 07:45:48

问题


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?


回答1:


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




回答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))



回答3:


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.



来源:https://stackoverflow.com/questions/4556814/java-net-malformedurlexception-no-protocol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!