简体   繁体   English

如何从远程服务器为位于apache-tomcat WEB-INF / lib文件夹下的jar文件制作下载URL?

[英]How to make a download url for the jar file located under apache-tomcat WEB-INF/lib folder from remote server?

Can anyone please tell me how to create a download link for a jar file which is located under /WEB-INF/lib folder of apache-tomcat . 谁能告诉我如何为jar文件创建下载链接,该文件位于apache-tomcat /WEB-INF/lib文件夹下。 I am able to get the following jar file location as: 我能够获得以下jar文件位置:

jar:file:/var/lib/tomcat7/webapps/cs/WEB-INF/lib/commons-fileupload-1.3.1.jar!/org/apache/commons/fileupload/disk/DiskFileItem.class

I want to build a download URL for this jar file so that I can download it from remote server to my local hard disk. 我想为此jar文件构建一个下载URL,以便可以将其从远程服务器下载到本地硬盘。

I have following code for finding java-version: 我有以下代码可找到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;
  }
}

You can't access straight to any resource under WEB-INF folder, since it is protected by tomcat from url access requests. 您无法直接访问WEB-INF文件夹下的任何资源,因为它受到Tomcat的保护,无法访问URL。

If you need to access any resource from within WEB-INF, you should build a java component (servlet, filter, controller, etc) to access this WEB-INF elements and return them. 如果您需要从WEB-INF中访问任何资源,则应该构建一个Java组件(servlet,过滤器,控制器等)来访问此WEB-INF元素并返回它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WEB-INF / lib中的Tomcat自定义库jar文件 - Tomcat custom library jar file in WEB-INF/lib 自动将新的Jar文件复制到Tomcat项目WEB-INF / lib文件夹中 - Automatically copy new Jar file to Tomcat project WEB-INF/lib folder 在eclipse中运行tomcat时,不会从WEB-INF / lib中的jar文件加载spring web应用程序上下文 - spring web application context is not loaded from jar file in WEB-INF/lib when running tomcat in eclipse 如何将.class下的web-inf / classs打包为jar并将其放入web-inf / lib目录 - how to package the .class under the web-inf/classes as a jar and put it to the web-inf/lib dir 在JBOSS 7中,war文件可以访问ear / lib而非Web-inf / lib中的jar文件 - In JBOSS 7 can war file access a jar file located in ear/lib instead of web-inf/lib 如何将 JAR 文件添加到现有的 WAR 文件 web-inf/lib 文件夹中? - How to add JAR file to an existing WAR file web-inf/lib folder? 从web-inf \\ lib \\ *。jar中的代码文件加载 - Load from code file from web-inf\lib\*.jar 将Jar文件添加到WEB-INF / lib - Adding Jar File to WEB-INF/lib tomcat / lib或WEB-INF / lib中不需要的jar文件 - Unwanted jar files in tomcat/lib or WEB-INF/lib 如何将inputstream转换为java中tomcat中web-inf文件夹下的配置文件? - how to get the inputstream to configuration file lying under web-inf folder in tomcat in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM