java.net.MalformedURLException:无协议
我正在编写一个类来在 java 中运行 xjc。我的代码如下:
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")));
但是,当我运行此代码时,出现以下错误:
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)
任何人都可以帮忙解决这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将
"file://"
附加到文件路径的开头。但正如 Bozho 提议的那样,您不需要此处的 URL。Try append
"file://"
to the beginning of your file path. But as Bozho proposed, you don't need an URL here.这不是有效的 URL。可以通过在前面添加
file://
作为协议来使其有效。但您根本不需要 URL。您可以将
Reader
(以及InputStream
)传递给InputSource
构造函数。例如: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 anInputStream
) to theInputSource
constructor. So for example:我在打开虚拟控制台时有上述情况。
解决方案:您在浏览器中选择了非常安全的选项。
开始--> Java 配置 --> 安全性 -- 点击 - 非常高。
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.