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

发布于 2024-09-06 06:51:44 字数 181 浏览 11 评论 0原文

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

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

I am getting a too long line error while trying to build a jar. the long line in the manifest file is the Class-Path line as the application uses a lot of third-party libraries. needless to say, I am using Windows :-( and Eclipse Java 1.6

I tried Class-Path: lib or Class-Path: lib/ but they did not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

半衬遮猫 2024-09-13 06:51:44

由于类路径中的 jar 文件数量较多,类路径太长。 “以 UTF8 编码形式,任何行的长度都不能超过 72 个字节(不是字符)。” [来自文档:java 5java 8; “线长度”部分]。

使用以下方法解决该问题:

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

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

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

The classpath is too long due to the number of jar files in it. «No line may be longer than 72 bytes (not characters), in its UTF8-encoded form.» [from docs: java 5, java 8; «Line length» section].

use as the following way to resolve the problem:

(1) use separate lines, to avoid too long a line for java package name lists

(2) type a preceding space before each folloing lines, for example:

Class-Path:
 ...jar
 ...jar
 ...jar
冷清清 2024-09-13 06:51:44

单个字符对我来说不起作用(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 文件中生成的清单文件时,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

The single character didn't work for me (Java 8, IntelliJ). I used two characters at the start and no characters at the end of the line (wasn't apparent from the above example) and two new lines at the end, e.g.

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

I also avoided placing multiple jars on one line as that didn't appear to work (even with lines less than 72 bytes).

What led me to arrive at this solution was (1) I kept getting various class not found exceptions, of course and (2) When I examined the generated manifest file in the jar file, the spacing between the jars was missing - I assume that it was silently failing because there was no reported error apart from the class not found exceptions. My working, generated manifest file looks like this:

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
霓裳挽歌倾城醉 2024-09-13 06:51:44

Voodoochild 的答案让我走上了正轨,但对我来说不太清楚,所以引用了规范:

没有一行可以超过 72 个字节(不是字符),以 UTF8 编码的形式。如果某个值会使初始行比此长,则应在额外的行上继续(每行以单个空格开头)。

清单示例:

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 

The answer of Voodoochild put me on the right track but wasn't so clear to me so quoting the specs:

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 example:

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 
夜光 2024-09-13 06:51:44

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

The multi-space solutions up there didn't work for me for some reason. So I looked at how Eclipse's export-runnable-jar dialog does it. It adds an Ascii "LF" and then a space as a linebreak.
In Java: char LF = (char) 0x0A;

邮友 2024-09-13 06:51:44

对于太长的行错误

使用类路径:*.*

For too long line error

Use Class-Path: *.*

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文