1、创建 Liferay Workspace project 命名demo(自定义),Build type默认Gradle。

结构如下:

gradle.properties文件中添加服务器配置 liferay.workspace.home.dir=D:/liferaydevelop/tomcat/liferay-ce-portal-7.0-ga3

2、添加server,点击add;

配置server,tomcat服务器路径,Jdk路径,start/debug;

3、在demo下的modules文件夹下,新建Liferay Module Project 命名rest,Project Template Name 选择“rest”


build.gradle文件中,添加项目所依赖的jar(本地/在线);
bnd.bnd文件中,自动生成的配置路径不可用,修改成下面的方式;

自动生成Rest1Application 文件,代码如下:
/**
* @author photo
*/
@ApplicationPath("/greetings")
@Component(immediate = true, service = Application.class)
public class Rest1Application extends Application {
public Set<Object> getSingletons() {
return Collections.<Object>singleton(this);
}
@GET
@Produces("text/plain")
public String working() {
return "It works!";
}
@GET
@Path("/morning")
@Produces("text/plain")
public String hello() {
return "Good morning!";
}
@GET
@Path("/morning/{name}")
@Produces("text/plain")
public String morning(
@PathParam("name") String name,
@QueryParam("drink") String drink) {
String greeting = "Good Morning " + name;
if (drink != null) {
greeting += ". Would you like some " + drink + "?";
}
return greeting;
}
}
4、使用“clean”,“deploy” 刷新生成jar 包;

5、浏览器访问




网友评论