[英]How to make a download url for the jar file located under apache-tomcat WEB-INF/lib folder from remote server?
谁能告诉我如何为jar文件创建下载链接,该文件位于apache-tomcat
/WEB-INF/lib
文件夹下。 我能够获得以下jar文件位置:
jar:file:/var/lib/tomcat7/webapps/cs/WEB-INF/lib/commons-fileupload-1.3.1.jar!/org/apache/commons/fileupload/disk/DiskFileItem.class
我想为此jar文件构建一个下载URL,以便可以将其从远程服务器下载到本地硬盘。
我有以下代码可找到Java版本:
public static Map<String, String> getJarVersions(ICS ics, ServletContext context)
{
ServletContextResource resource = new ServletContextResource(context, "/WEB-INF/lib/");
File file = null;
try
{
file = resource.getFile();
}
catch (IOException e)
{
log.error("Error reading /WEB-INF/lib/ directory. ", e);
return new HashMap(0);
}
File[] jarFiles = file.listFiles();
Map<String, String> jarNameVersion = new HashMap();
File[] arr$ = jarFiles;int len$ = arr$.length;
for (int i$ = 0; i$ < len$;)
{
File jarFile = arr$[i$];
JarFile jarfile = null;
Manifest manifest = null;
try
{
jarfile = new JarFile(jarFile);
manifest = jarfile.getManifest();
if (manifest != null)
{
Attributes attrs = manifest.getMainAttributes();
String version = attrs.getValue("Implementation-Version");
String vendor = attrs.getValue("Implementation-Vendor");
if (vendor == null) {
vendor = "Not applicable";
}
if (version == null) {
version = "Not applicable";
}
version = version + " : " + vendor;
jarNameVersion.put(jarFile.getName(), version);
}
else
{
jarNameVersion.put(jarFile.getName());
}
if (jarfile != null) {
try
{
jarfile.close();
}
catch (IOException e)
{
log.error("Error thrown while closing the jar file ");
}
}
i$++;
}
catch (IOException e)
{
log.error("Error reading JAR/MANIFEST file . ", e);
}
finally
{
if (jarfile != null) {
try
{
jarfile.close();
}
catch (IOException e)
{
log.error("Error thrown while closing the jar file ");
}
}
}
}
return jarNameVersion;
}
}
您无法直接访问WEB-INF文件夹下的任何资源,因为它受到Tomcat的保护,无法访问URL。
如果您需要从WEB-INF中访问任何资源,则应该构建一个Java组件(servlet,过滤器,控制器等)来访问此WEB-INF元素并返回它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.