由于公司的代码库中使用的restlet版本较老,在central和restlet库中都无法找到。
在maven项目中使用时,需要手动添加到本地库中,十分繁琐。因此决定使用新版本替换。
实验环境:
- JDK 1.8
添加依赖
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>qiuqiu</groupId>
<artifactId>restlet</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>maven-restlet</id>
<name>Public online Restlet repository</name>
<url>http://maven.restlet.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.restlet.jee</groupId>
<artifactId>org.restlet</artifactId>
<version>2.3.10</version>
</dependency>
</dependencies>
</project>
注意:在 central
库中无法找到,需要添加 restlet
库。
代码示例
第一个
直接拿官方的示例~
package restlet;
import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
public class FirstServerResource extends ServerResource {
public static void main(String[] args) throws Exception {
// Create the HTTP server and listen on port 8182
new Server(Protocol.HTTP, 8182, FirstServerResource.class).start();
}
@Get
public String toString() {
return "hello, world";
}
}
运行后,在浏览器中访问 http://localhost:8182
访问 http://localhost:8182/aaa/ddd
可见,这里是设置了一个默认的返回值。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。