1

以下是我的 Ant 构建文件内容:

<?xml version="1.0"?>
<project name="testant"
         basedir=".">
  <property file="build.properties" />
  <target name="manifest">
    <tstamp />
    <manifest mode="update"
              file="manifest.mf">
      <attribute name="Built-By"
                 value="${user.name}" />
      <section name="common">
        <attribute name="Specification-Title"
                   value="${ant.project.name}" />
        <attribute name="Specification-Version"
                   value="1.0.0" />
        <attribute name="Specification-Vendor"
                   value="" />
        <attribute name="Implementation-Title"
                   value="" />
        <attribute name="Implementation-Version"
                   value="${TODAY}" />
        <attribute name="Implementation-Vendor"
                   value="" />
      </section>
      <attribute name="Main-Class"
                 value="${main.class}" />
    </manifest>
  </target>
</project>

以下是我的 build.properties。

packages=com.javacodegeeks.patterns.strategypattern.*
main.class=com.javacodegeeks.patterns.strategypattern.TestStrategyPattern

以下是我的输出 manifest.mf。

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.10.6
Created-By: 10.0.2+13 (Oracle Corporation)
Built-By: root
Main-Class: com.javacodegeeks.patterns.strategypattern.TestStrategyPat
 tern

Name: common
Specification-Title: testant
Specification-Version: 1.0.0
Specification-Vendor: 
Implementation-Title: 
Implementation-Version: July 7 2019
Implementation-Vendor: 

为什么主类名中会产生空格?

它不影响使用 ant 任务或 jar 命令生成 jar 文件。

可执行 jar 也可以按预期工作。

4

1 回答 1

1

根据 JAR 规范

  • 线长:

    • 采用 UTF8 编码格式的行不得超过 72 个字节(不是字符)。如果一个值会使初始行比这长,它应该在额外的行上继续(每行都以一个空格开头)。

一些工具似乎无视这一要求,但 Ant 对此要求严格。您的行包含 70 个字符加上大概\r\n.

于 2019-07-07T05:22:32.030 回答