相关疑难解决方法(0)

如何在生产中测试和运行jar时创建一个可用的MANIFEST.MF?

我花了太多时间试图解决这个问题.这应该是最简单的事情,每个在Java中分发Java应用程序的人都必须处理它.

我只是想知道向我的Java应用程序添加版本控制的正确方法,以便我可以在测试时访问版本信息,例如在Eclipse中调试从jar运行.

这是我在build.xml中的内容:

<target name="jar" depends = "compile">
    <property name="version.num" value="1.0.0"/>
    <buildnumber file="build.num"/>
    <tstamp>
        <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
    </tstamp>

    <manifest file="${build}/META-INF/MANIFEST.MF">
        <attribute name="Built-By" value="${user.name}" />
        <attribute name="Built-Date" value="${TODAY}" />                   
        <attribute name="Implementation-Title" value="MyApp" />
        <attribute name="Implementation-Vendor" value="MyCompany" />                
        <attribute name="Implementation-Version" value="${version.num}-b${build.number}"/>                              
    </manifest>

    <jar destfile="${build}/myapp.jar" basedir="${build}" excludes="*.jar" />                   
</target>
Run Code Online (Sandbox Code Playgroud)

这创建了/META-INF/MANIFEST.MF,我可以在Eclipse中调试时读取值:

public MyClass()
{
    try
    {                        
        InputStream stream = getClass().getResourceAsStream("/META-INF/MANIFEST.MF");
        Manifest manifest = new Manifest(stream);            

        Attributes attributes = manifest.getMainAttributes();

        String implementationTitle = attributes.getValue("Implementation-Title");
        String implementationVersion = attributes.getValue("Implementation-Version");
        String builtDate = …
Run Code Online (Sandbox Code Playgroud)

java versioning ant jar manifest.mf

20
推荐指数
2
解决办法
3万
查看次数

标签 统计

ant ×1

jar ×1

java ×1

manifest.mf ×1

versioning ×1