尝试创建jar时清单文件中的行太长

问题描述 投票:14回答:5

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

我试过Class-Path: libClass-Path: lib/,但他们没有用。

java jar classpath manifest
5个回答
34
投票

由于其中包含jar文件的数量,类路径太长。 «以UTF8编码的形式,没有行可能长于72个字节(不是字符)。»[来自docs:java 5java 8; «线长»部分]。

使用以下方法解决问题:

(1)使用单独的行,避免一行为java包名列表

(2)在每个后续行之前键入前一个空格,例如:

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

6
投票

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 

6
投票

单个字符对我不起作用(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

我还避免在一行上放置多个罐子,因为它似乎不起作用(即使行数少于72个字节)。

让我得出这个解决方案的原因是(1)我一直得到各种类未找到的异常,当然和(2)当我在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

0
投票

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


-7
投票

太长的线路错误

使用Class-Path:*.*

© www.soinside.com 2019 - 2024. All rights reserved.