【问题标题】:Get manifest info of remote jars获取远程 jar 的清单信息
【发布时间】:2012-01-25 09:29:07
【问题描述】:

我必须处理在没有适当发布策略的情况下在各种服务器环境中发布多个 jar 的情况。

这意味着,除非我明确检查,否则我无法知道在给定服务器上发布了哪个版本。

我正在推动制定这样的政策,但在那之前我一无所知。

无论如何,我设法在构建脚本中插入了一些基本信息(时间戳、运行构建的用户)的价值,所以我有一些基本数据来控制情况。

我想做的是阅读这些信息,然后创建一份报告告诉我总体情况。

我当然可以通过两种方式自己编写脚本: - 从每个服务器下载 jars 并提取清单信息; - 运行提取清单并返回信息的远程实用程序。

是否有一些工具/脚本/ant-task 可以完成这项任务,还是我应该自己写一个?

【问题讨论】:

  • 我不知道 ant 中有任何现有的解决方案。

标签: java ant jar versioning


【解决方案1】:

您不知何故需要进入每个罐子。如果您知道它们的位置,假设它们都部署在一个位置(或根文件夹)下,您可以拥有一个脚本,该脚本可能会使用 jar、grepfind 的某种组合.

for i in *.jar; do jar -tvf .... 

我真的想不出其他方法。

【讨论】:

    【解决方案2】:

    我在这里找到了部分答案:

    Ant Task to read directly from a JAR Manifest file

    <project>
    
        <!-- Get a jar -->
        <copy file="${ant.home}/lib/ant.jar" todir="."/>
    
        <!--
        Loads entries from a manifest file.
        @jar     The jar from where to read
        @prefix  A prefix to prepend
        -->
        <macrodef name="loadmf">
            <attribute name="jar"/>
            <attribute name="prefix" default=""/>
            <sequential>
                <loadproperties>
                    <!-- Load the manifest entries -->
                    <zipentry zipfile="@{jar}" name="META-INF/MANIFEST.MF"/>
                    <!-- Add the prefix -->
                    <filterchain>
                        <prefixlines prefix="@{prefix}"/>
                    </filterchain>
                </loadproperties>
            </sequential>
        </macrodef>
    
        <!-- Read mf entries -->
        <loadmf jar="ant.jar" prefix="ant-mf."/>
        <!-- Print them -->
        <echoproperties prefix="ant-mf."/>
    
    </project>
    

    它几乎做到了它所说的。

    输出类似于:

    Buildfile: C:\dev\ant\build.xml
         [copy] Copying 1 file to C:\dev\ant
    [echoproperties] #Ant properties
    [echoproperties] #Wed Jan 25 12:02:09 CET 2012
    [echoproperties] ant-mf.=
    [echoproperties] ant-mf.Ant-Version=Apache Ant 1.8.1
    [echoproperties] ant-mf.Created-By=1.5.0_22-b03 (Sun Microsystems Inc.)
    [echoproperties] ant-mf.Extension-name=org.apache.tools.ant
    [echoproperties] ant-mf.Implementation-Title=org.apache.tools.ant
    [echoproperties] ant-mf.Implementation-Vendor=Apache Software Foundation
    [echoproperties] ant-mf.Implementation-Version=1.8.1
    [echoproperties] ant-mf.Main-Class=org.apache.tools.ant.Main
    [echoproperties] ant-mf.Manifest-Version=1.0
    [echoproperties] ant-mf.Name=org/apache/tools/ant/
    [echoproperties] ant-mf.Specification-Title=Apache Ant
    [echoproperties] ant-mf.Specification-Vendor=Apache Software Foundation
    [echoproperties] ant-mf.Specification-Version=1.8.1
    
    BUILD SUCCESSFUL
    Total time: 2 seconds
    

    这是我完成任务所需的基本内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 2021-10-28
      • 2020-02-05
      • 2017-10-16
      相关资源
      最近更新 更多