我正在研究“Restlet in action”一书中的示例。我不使用任何IDE,Maven或其他东西。只是一个纯粹的命令行。问题显示资源类别:我应该添加多少罐以使应用程序正常工作?
import java.io.IOException;
import org.restlet.data.Reference;
import org.restlet.ext.jackson.JacksonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.Put;
import org.restlet.resource.ServerResource;
public class MailServerResource extends ServerResource {
@Get
public Representation toJson() {
// Create the mail bean
Mail mail = new Mail();
mail.setStatus("received");
mail.setSubject("Message to self");
mail.setContent("Doh!");
mail.setAccountRef(new Reference(getReference(), "..").getTargetRef()
.toString());
// Wraps the bean with a Jackson representation
return new JacksonRepresentation<Mail>(mail);
}
@Put
public void store(Representation rep) throws IOException {
// Parse the JSON representation to get the mail bean
JacksonRepresentation<Mail> mailRep = new JacksonRepresentation<Mail>(
rep, Mail.class);
Mail mail = mailRep.getObject();
// Output the JSON element values
System.out.println("Status: " + mail.getStatus());
System.out.println("Subject: " + mail.getSubject());
System.out.println("Content: " + mail.getContent());
System.out.println("Account URI: " + mail.getAccountRef());
}
}
包含此类的应用程序可以被编译。但我有一个运行时异常,指出缺少的库。每次添加缺失的库时,我都会得到新的和新的异常,迫使我添加新的和新的库。它似乎是无止境的。例如:
- 第一次编译和运行应用程序的结果:OK。运行时错误而试图从浏览器中的资源:
org.restlet.resource.ResourceException:内部服务器错误(500)产生的原因:java.lang.NoClassDefFoundError:COM/fasterxml /杰克逊/核心/ JsonFactory
- 将com.fasterxml.jackson.core.jar添加到编译命令并运行命令后的结果:OK。运行时错误:
由java.lang.NoClassDefFoundError致毒相同的错误:COM/fasterxml /杰克逊/ DATAFORMAT /微笑/ SmileFactory
加入COM后- 结果。使用fasterxml.jackson.smile.jar编译命令并运行命令:OK。运行时错误:
- 加入com.fasterxml之后的结果。 jackson.databind.jar编译命令并运行命令:OK。运行时错误:
- 添加jackson-dataformat-xml-2.8.5.jar编译命令并运行命令后的结果:好。运行时错误:
由java.lang.NoClassDefFoundError致毒相同的错误:COM/fasterxml /杰克逊/数据绑定/ ObjectMapper
相同的错误由java.lang.NoClassDefFoundError致毒:COM/fasterxml /杰克逊/ DATAFORMAT/XML/XmlMapper
而且因为这个库中的Restlet框架中缺失的这看起来很奇怪。所以我希望它不应该用在本书的例子中。但我无论如何去添加这个从网上下载的库:
由java.lang.NoClassDefFoundError致毒了同样的错误:COM/fasterxml /杰克逊/ DATAFORMAT/YAML/YAMLFactory
我放弃,请你帮忙......
请注意,您不需要为编译命令添加额外的依赖关系 - 只要它编译成功,编译时类路径就是正确的,从那时起,您只需将额外的依赖关系添加到运行时类路径中即可。 – haggisandchips