Castor编译问题
当我尝试使用 Marshal 和 unmarshal 时,我从编译器中收到“无法访问 org.exolab.castor.core.exceptions.CastorException”。我用的是Castor 1.3
try {
Writer writer = new FileWriter("out.xml");
Marshaller.marshal(person, writer);
Reader reader = new FileReader("out.xml");
metaType = (Person) Unmarshaller.unmarshal(Person.class, reader);
}catch (MarshalException e) {
} catch (ValidationException e) {
}
I got "cannot access org.exolab.castor.core.exceptions.CastorException" from the compiler when I try to use Marshal and unmarshal. I used Castor 1.3
try {
Writer writer = new FileWriter("out.xml");
Marshaller.marshal(person, writer);
Reader reader = new FileReader("out.xml");
metaType = (Person) Unmarshaller.unmarshal(Person.class, reader);
}catch (MarshalException e) {
} catch (ValidationException e) {
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,这不是异常,这是编译错误。该代码甚至无法成为可运行的
.class
文件。这是一个巨大的差异。将来你应该尝试更明确地表达这一点。这个编译错误实际上意味着编译时类路径中缺少提到的类。如果您使用
javac
进行编译,则需要将 Castor JAR 文件的完整路径添加到-cp
(类路径)参数中,其中包含提到的类。像这样的东西:那是一个 Windows 示例;在 Unix/Linux 和克隆中,您需要
:
作为路径分隔符。内部带有空格的各个路径应该用引号引起来。First of all, this is not an exception, this is a compilation error. The code isn't even able to become a runnable
.class
file. That's a huge difference. In the future you should try to be more explicit about that.This compilation error actually means that the mentioned class is missing in the classpath during compiletime. If you're compiling using
javac
, then you need to add the full path to the Castor JAR file which includes the mentioned class to the-cp
(classpath) argument. Something like this:That was a Windows Example; in Unix/Linux and clones you need
:
as path separator. Individual paths with spaces inside should be enclosed by quotes.