使用Jersey JAX RS.WS获取Java中的当前web文件夹

使用Jersey JAX RS.WS获取Java中的当前web文件夹,java,web-services,rest,jax-ws,glassfish-4,Java,Web Services,Rest,Jax Ws,Glassfish 4,这似乎很简单,但似乎我在谷歌找不到答案。 我需要发送webroot文件夹中的文件列表,类似于目录浏览 我使用Glassfish、JAX-RS.WS和genson作为pojowriter 应用程序结构如下: download |- build |- dist |- src |- web | |- files 下面是我的代码 @Path("home") public class HomeResource { @Context private UriInfo context;

这似乎很简单,但似乎我在谷歌找不到答案。 我需要发送webroot文件夹中的文件列表,类似于目录浏览

我使用Glassfish、JAX-RS.WS和genson作为pojowriter

应用程序结构如下:

download
|- build
|- dist
|- src
|- web
|  |- files
下面是我的代码

@Path("home")
public class HomeResource {

    @Context
    private UriInfo context;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String get() {
        return System.getProperty("user.dir"); // ??? Any idea what should be in here?
    }
}
结果是:

/usr/lib/glassfish/glassfish/domains/domain1/config
我需要它指向

/sites/download/web/
或者至少

/sites/download/
因为我需要我的服务提供一个列表,例如:

/files/item.zip
/files/document.pdf
任何人都可以帮忙吗

谢谢

您可以从

在我的eclipse管理的Tomcat实例中,请求
/JaxRsRealPath/sample?path=/WEB-INF
会生成请求的文件或文件夹的实际文件系统路径-可用于
java.io.file

Hello, world! 
Requested path: /WEB-INF
Actual path: /Users/scotth/Workspaces/eclipse45-default/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JaxRsRealPath/WEB-INF/
另一个仅请求
/jaxrrealpath/sample
(然后代码检查到上下文根目录的路径
/
)的示例:

如果需要,可以从中使用获取文件的目录列表

Hello, world! 
Requested path: /WEB-INF
Actual path: /Users/scotth/Workspaces/eclipse45-default/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JaxRsRealPath/WEB-INF/
Hello, world! 
Requested path: /
Actual path: /Users/scotth/Workspaces/eclipse45-default/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JaxRsRealPath/