Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 错误:ClassNotFoundException_Java_Rest - Fatal编程技术网

Java 错误:ClassNotFoundException

Java 错误:ClassNotFoundException,java,rest,Java,Rest,我正在尝试为下载zip文件编写RESTAPI。我得到了下面的例外java.lang.ClassNotFoundException:org.glassfish.jersey.internal.RuntimeDelegateImpl。 我已经在我的pom.xml文件中定义了以下依赖项 <dependency> <groupId>org.glassfish.jersey.core</groupId> <artif

我正在尝试为下载zip文件编写RESTAPI。我得到了下面的例外
java.lang.ClassNotFoundException:org.glassfish.jersey.internal.RuntimeDelegateImpl
。 我已经在我的
pom.xml
文件中定义了以下依赖项

<dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-common</artifactId>
            <version>2.22.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
        </dependency>`

当我点击邮递员的URL时,我得到了上面的例外。是什么导致了错误

你只为单元测试编译那个类?@cricket_007我删除了
测试
,现在我没有得到任何错误。现在,当我点击URL时,我得到了json响应。如何下载文件,你可以给出一些想法这是我得到的回应:
{“实体”:“C:\\VarunDoc\\Full\u Zip.Zip”,“状态”:200,“元数据”:{“内容配置”:[“附件;文件名=Full\u Zip.Zip”]},“注释”:null,“entityClass”:“java.io.file”,“genericType”:null,“长度”:-1,“语言”:null,“位置”:null,“lastModified”:null,“日期”:null,“cookies”:{},“mediaType”:null,“closed”:false,“allowedMethods”:[],“links”:[],“statusInfo”:“OK”,“stringHeaders”:{“Content Disposition”:[“attachment;filename=Full_Zip.Zip”]},“entityTag”:null,“headers”:{“Content Disposition”:[“attachment;filename=Full_Zip.Zip”]}
不确定为什么会得到json。。。您的响应应该是八位字节流或文件,而不是json
@GET
@RequestMapping(value="/zip")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadZip() {
    String FILE_PATH = "C:\\VarunDoc\\Full_Zip.zip";
    File file = new File(FILE_PATH);
    ResponseBuilder response = Response.ok((Object) file);
    response.header("Content-Disposition", "attachment; filename=Full_Zip.zip");
    return response.build();
}