[英]java.net.MalformedURLException: no protocol
I' m writing a class to run xjc in java. 我正在编写一个在java中运行xjc的类。 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? 有人可以帮忙吗?
Try append "file://"
to the beginning of your file path. 尝试将
"file://"
附加到文件路径的开头。 But as Bozho proposed, you don't need an URL here. 但正如Bozho所建议的那样,你不需要这里的URL。
This is not a valid URL. 这不是有效的URL。 It can be made valid by prepending
file://
as protocol. 它可以通过预先添加
file://
作为协议来使其有效。
But you don't need a URL at all. 但是你根本不需要URL。 You can pass a
Reader
(as well as an InputStream
) to the InputSource
constructor. 您可以将
Reader
(以及InputStream
)传递给InputSource
构造函数。 So for example: 例如:
new InputSource(new FileReader(path))
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. 开始 - > Java配置 - >安全--Cilick on - 非常高。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.