【问题标题】:Too long line in manifest file while trying to create jar尝试创建 jar 时清单文件中的行太长
【发布时间】:2011-03-04 17:23:17
【问题描述】:

我在尝试构建 jar 时遇到了一个太长的行错误。清单文件中的长行是 Class-Path 行,因为应用程序使用了很多第三方库。不用说,我使用的是 Windows :-( 和 Eclipse Java 1.6

我尝试了Class-Path: libClass-Path: lib/,但它们不起作用。

【问题讨论】:

    标签: java jar classpath manifest


    【解决方案1】:

    由于 jar 文件的数量,类路径太长。 «任何行不得超过 72 个字节(不是字符),采用 UTF8 编码形式。» [来自文档:java 5java 8; «行长»部分]。

    使用如下方式解决问题:

    (1) 使用单独的行,以避免java包名列表的行太长

    (2) 在后面的每一行之前输入一个空格,例如:

    Class-Path:
     ...jar
     ...jar
     ...jar
    

    【讨论】:

    • 完美...每行末尾一个空格,开头一个空格。谢谢一百万
    • @fadmaa,仅在开头。
    【解决方案2】:

    单个字符对我不起作用(Java 8、IntelliJ)。我在开头使用了两个字符,在行尾没有字符(从上面的示例中看不到),在结尾使用了两个新行,例如

    Manifest-Version: 1.0
    Main-Class: com.mypackage.MyApp
    Implementation-Version: 2.0.0
    Class-Path:  newLibs/asjava.zip
      newLibs/activation.jar
      newLibs/axis-ant.jar
      newLibs/axis.jar
      newLibs/bcel-5.1.jar
      newLibs/commons-discovery-0.2.jar
      newLibs/commons-logging-1.0.4.jar
      newLibs/datanucleus-api-jdo-4.2.0-release.jar
      newLibs/datanucleus-api-jpa-4.1.4.jar
      newLibs/datanucleus-cache-4.0.4.jar
      newLibs/datanucleus-core-4.1.5.jar
      newLibs/datanucleus-geospatial-4.1.0-release.jar
      newLibs/datanucleus-guava-4.1.3.jar
      newLibs/datanucleus-java8-4.2.0-release.jar
      newLibs/datanucleus-jdo-query-4.2.0-release.jar
      newLibs/datanucleus-jodatime-4.1.1.jar
      newLibs/datanucleus-jpa-query-4.0.4.jar
      newLibs/datanucleus-rdbms-4.1.6.jar
      newLibs/dom4j-1.6.1.jar
      newLibs/ehcache-1.1.jar
      newLibs/ehcache-core-2.2.0.jar
      newLibs/geronimo-jta_1.1_spec-1.1.jar
      newLibs/guava-15.0.jar
      newLibs/h2-1.3.168.jar
      newLibs/ibmjsse.jar
      newLibs/javax.jdo-3.2.0-m3.jar
      newLibs/javax.persistence-2.1.1.jar
      newLibs/jaxrpc.jar
      newLibs/jdo-api-3.1-rc1.jar
      newLibs/jdom.jar
      newLibs/joda-time-1.6.jar
      newLibs/jtds-1.2.jar
      newLibs/log4j-1.2.14.jar
      newLibs/mail.jar
      newLibs/saaj.jar
      newLibs/servlet-api.jar
      newLibs/wsdl4j-1.5.1.jar
      newLibs/xercesImpl.jar
      newLibs/xml-apis.jar
    

    我还避免在一行中放置多个 jar,因为这似乎不起作用(即使行少于 72 字节)。

    导致我得出这个解决方案的原因是(1)我不断收到各种类未找到异常,当然,(2)当我检查 jar 文件中生成的清单文件时,jar 之间的间距丢失了 -我认为它是静默失败,因为除了类未找到异常之外没有报告错误。我的工作,生成的清单文件如下所示:

    Manifest-Version: 1.0
    Implementation-Version: 2.0.0
    Class-Path:  newLibs/asjava.zip newLibs/activation.jar newLibs/axis-an
     t.jar newLibs/axis.jar newLibs/bcel-5.1.jar newLibs/commons-discovery
     -0.2.jar newLibs/commons-logging-1.0.4.jar newLibs/datanucleus-api-jd
     o-4.2.0-release.jar newLibs/datanucleus-api-jpa-4.1.4.jar newLibs/dat
     anucleus-cache-4.0.4.jar newLibs/datanucleus-core-4.1.5.jar newLibs/d
     atanucleus-geospatial-4.1.0-release.jar newLibs/datanucleus-guava-4.1
     .3.jar newLibs/datanucleus-java8-4.2.0-release.jar newLibs/datanucleu
     s-jdo-query-4.2.0-release.jar newLibs/datanucleus-jodatime-4.1.1.jar 
     newLibs/datanucleus-jpa-query-4.0.4.jar newLibs/datanucleus-rdbms-4.1
     .6.jar newLibs/dom4j-1.6.1.jar newLibs/ehcache-1.1.jar newLibs/ehcach
     e-core-2.2.0.jar newLibs/geronimo-jta_1.1_spec-1.1.jar newLibs/guava-
     15.0.jar newLibs/h2-1.3.168.jar newLibs/ibmjsse.jar newLibs/javax.jdo
     -3.2.0-m3.jar newLibs/javax.persistence-2.1.1.jar newLibs/jaxrpc.jar 
     newLibs/jdo-api-3.1-rc1.jar newLibs/jdom.jar newLibs/joda-time-1.6.ja
     r newLibs/jtds-1.2.jar newLibs/junit-3.8.1.jar newLibs/log4j-1.2.14.j
     ar newLibs/mail.jar newLibs/saaj.jar newLibs/servlet-api.jar newLibs/
     wsdl4j-1.5.1.jar newLibs/xercesImpl.jar newLibs/xml-apis.jar
    Main-Class: com.mypackage.MyApp
    

    【讨论】:

    • 这种文件格式的气质性质令人难以置信,但似乎紧跟在Class-Path: 之后的两个空格在行尾和每行之前一个空格,最后是一个额外的新空格-line 最后的伎俩。哇,我想我现在要给自己倒点烈酒了。
    【解决方案3】:

    Voodoochild 的回答让我走上了正轨,但对我来说不是很清楚,所以引用了规格:

    No line may be longer than 72 bytes (not characters), in its UTF8-encoded form. If a value would make the initial line longer than this, it should be continued on extra lines (each starting with a single SPACE).

    清单示例:

    Manifest-Version: 1.0
    Main-Class: com.mypackage.MyApp
    Class-path: commons-beanutils-1.7.0.jar commons-collections-3.1.jar
     commons-dbcp-1.2.2.jar commons-discovery.jar commons-lang-2.1.jar
     commons-pool-1.2.jar ezjcom18.jar jbcl.jar log4j-1.2.14.jar
     sqljdbc.jar torque-3.2-rc2.jar 
    

    【讨论】:

    • 另外,如果 jar 文件的名称超过 72 个字节并延续到下一行,它不应该有多余的单个空格(我修改了您的示例以包含这种情况)。
    【解决方案4】:

    由于某种原因,上面的多空间解决方案对我不起作用。所以我查看了 Eclipse 的 export-runnable-jar 对话框是如何做到的。它添加一个 Ascii “LF”,然后添加一个空格作为换行符。 在 Java 中:char LF = (char) 0x0A;

    【讨论】:

      【解决方案5】:

      对于太长的行错误

      使用类路径:*.*

      【讨论】:

        猜你喜欢
        • 2021-07-14
        • 2012-12-26
        • 2012-09-22
        • 2014-09-01
        • 1970-01-01
        • 2010-11-27
        • 2011-11-14
        • 1970-01-01
        • 2014-12-12
        相关资源
        最近更新 更多