如何通过浏览器下载可执行的jar?



我无法打开下载的可执行 jar。我有一个网络应用程序,用于通过浏览器将 jar 下载到客户端。文件很好,但我收到消息:

Error: Invalid or corrupt jarfile  

我也无法打开文件 7zip .这是怎么回事?

该应用程序是一个JavaFx应用程序,可以在本地完美运行,但是当通过serlvet/浏览器传输时会损坏。

由于非常高的策略设置和由此产生的类加载问题,我也无法让 webstart 工作。

我的休息端点:

@RequestMapping(value = "/fetchTool", method = RequestMethod.GET)
@ResponseBody
public void downloadTool(HttpServletResponse response) throws IOException {
URL[] urls = ((URLClassLoader)(Thread.currentThread().getContextClassLoader())).getURLs();
Optional<URL> appPath = Arrays.stream(urls).filter(x->x.getPath().contains("myTool")).findFirst();
if (appPath.isPresent()){
String[] fileParts = appPath.get().getPath().split("/");

response.addHeader(CONTENT, ATTACHMENT + fileParts[fileParts.length - 1]);
response.setContentType("application/java-archive");
try (final InputStream input = new FileInputStream(appPath.get().getFile());
final OutputStream output = response.getOutputStream()) {
IOUtils.copy(input, output);
} catch (IOException e) {
throw new NotFoundException("File Not Found " + appPath.get().getPath(), e);
}
}else{
throw new NotFoundException("MyTool Not Found on classpath");
}
}

错误在 Angularjs 端,我没有将 responseType 设置为 arrayBuffer。

毕竟不在Java方面。

应该是 :

method: 'GET',
transformResponse: fileTransformer,
dataType:"binary",
processData : false,
responseType : 'arraybuffer',
headers: {
"Content-Type":undefined,
"accept": 'application/octet-stream'
}