简体   繁体   English

尝试打开罐子时发生意外错误

[英]An unexpected error occurred while trying to open jar

I have a spring batch project exported as a runable Jar file, it has 4 main methods, only one main is working, the other main needs referenced jar jai-codec-1.1.3.jar, but when I put the jar in the classpath, the first main also could not working and it gives error message "An unexpected error occurred while trying to open jar" 我有一个春季批处理项目导出为可运行的Jar文件,它有4个主要方法,只有一个主要正在工作,另一个主要需要引用jar jai-codec-1.1.3.jar,但是当我将jar放在类路径中时,第一个主电源也无法工作,并显示错误消息“尝试打开jar时发生意外错误”

here is my mainfest file: 这是我的mainfest文件:

Manifest-Version: 1.0 Class-Path: JARS/spring-jdbc-3.1.1.RELEASE.jar JARS/spring-context-3.2.3.RELEASE.jar JARS/log4j-1.2.14.jar JARS/spring-tx-3.2.3.RELEASE.jar JARS/spring-core-3.2.3.RELEASE.jar JARS/spring-beans-3.2.3.RELEASE.jar JARS/commons-logging-1.1.1.jar JARS/spring-aop-3.2.3.RELEASE.jar JARS/aopalliance-1.0.jar JARS/spring-expression-3.2.3.RELEASE.jar JARS/commons-dbcp-1.4.jar JARS/commons-pool-1.5.4.jar JARS/ojdbc6-11.2.0.3.jar JARS/commons-lang3-3.0.jar JARS/itextpdf-5.5.1.jar JARS/jdom2-2.0.5.jar JARS/jai-codec-1.1.3.jar 清单版本:1.0类路径:JARS / spring-jdbc-3.1.1.RELEASE.jar JARS / spring-context-3.2.3.RELEASE.jar JARS / log4j-1.2.14.jar JARS / spring-tx- 3.2.3.RELEASE.jar JARS / spring-core-3.2.3.RELEASE.jar JARS / spring-beans-3.2.3.RELEASE.jar JARS / commons-logging-1.1.1.jar JARS / spring-aop- 3.2.3.RELEASE.jar JARS / aopalliance-1.0.jar JARS / spring-expression-3.2.3.RELEASE.jar JARS / commons-dbcp-1.4.jar JARS / commons-pool-1.5.4.jar JARS / ojdbc6 -11.2.0.3.jar JARS / commons-lang3-3.0.jar JARS / itextpdf-5.5.1.jar JARS / jdom2-2.0.5.jar JARS / jai-codec-1.1.3.jar

I found out that it is not because the specific jar file, it is because the length of the classpath is exceeded the limit, is there a way to put more jars in the MAINFEST file classpath? 我发现这不是因为特定的jar文件,而是因为classpath的长度超出了限制,有没有办法在MAINFEST文件的classpath中放置更多的jar?

also I have defined all @autowired service and component classes but it still not working in jar, it only works when I defined those as bean in spring-config. 我也定义了所有@autowired服务和组件类,但是它仍然不能在jar中工作,只有当我在spring-config中将它们定义为bean时,它才起作用。

Anyone can Help me to figure out why? 任何人都可以帮助我找出原因吗?

Problem solved. 问题解决了。 I am not sure if it is the limitation of classpath size in MAINFEST file, but it really matters when it was too long, I changed all jar name as 1, 2 , 3... and be able to put all jars in the classpath, and it works. 我不确定这是否是MAINFEST文件中classpath大小的限制,但是当它太长时,这真的很重要,我将所有jar名称更改为1、2、3 ...,并能够将所有jar放在classpath中,并且有效。 Please leave your comments if you have different opinion on this, Thanks. 如果您对此有其他意见,请留下您的评论,谢谢。

This error may indicate (in a very unclear way though) error in MANIFEST.MF . 该错误可能表明(尽管以非常不清楚的方式) MANIFEST.MF错误。 This can be emulated by invalid empty line in the middle of the file or by lines too long. 这可以通过文件中间的无效空行或太长的行来模拟。

MANIFEST.MF is extremely manual-edit-unfriendly: MANIFEST.MF是极度手动编辑不友好的:

  • It must have final empty line (or final line terminator in other words), 它必须有最后一个空行(或换句话说,最后一个行终止符),
  • its lines must be 72 char long at most (I bet this was your true problem, you just fixed symptoms) 它的行最多不能超过72个字符(我敢打赌这是您的真正问题,只是解决了症状)
  • and continuation line must start with space... 延续线必须以空格开头...
  • and on top of it the classpath entries must be URLs, not file paths. 并且最重要的是,类路径条目必须是URL,而不是文件路径。

More about its specification can be found here: https://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html 有关其规范的更多信息,请参见: https : //docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html

I will add that Properties in Manifest MUST NOT be dot separated, either dash or no separator: "myProperty" will work, "my-property" will work too, but "my.property" will fail with "Error: An unexpected error occurred while trying to open file ..." with no explanation at all. 我将补充说,清单中的属性一定不能用点分隔,破折号或没有分隔符:“ myProperty”将起作用,“ my-property”也将起作用,但是“ my.property”将失败,并显示“错误:发生了意外错误”同时尝试打开文件...”,完全没有任何解释。 Although "my.property" would work as a Java property in some standalone application, it just breaks the launch of the embedded application inside a JAR when the Manifest is read. 尽管“ my.property”在某些独立的应用程序中可以用作Java属性,但是在读取清单时,它只是中断了JAR中嵌入式应用程序的启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以尝试/捕获此错误:“尝试打开jar时发生意外错误” - Can I try/catch this error: “An unexpected error occurred while trying to open jar” 我收到一个错误:尝试打开文件 hola.jar 时发生意外错误 - I get an error: An unexpected error occurred while trying to open file hola.jar Bundle-NativeCode:MANIFEST文件中的标头给出“错误:尝试打开文件pr.jar时发生意外错误” - Bundle-NativeCode: header in MANIFEST file give “Error: An unexpected error occurred while trying to open file pr.jar” 尝试对用户进行身份验证时发生内部错误 - An internal error occurred while trying to authenticate the user 尝试与sphero连接时发生错误 - An error occurred while trying to connect with the sphero 错误:执行jar文件时发生了JNI错误 - Error: A JNI error has occurred while executing jar file MYSQL&SQuirreL-尝试打开SQL连接时发生意外错误 - MYSQL & SQuirreL - Unexpected Error occurred attempting to open an SQL connection 在jar文件上执行主调用时发生错误 - Error occurred while execute main calls on jar file 执行从Maven构建的jar时出现“发生Java错误”消息 - “Java error occurred” message while executing a jar built from maven 尝试在 cmd 中运行可执行文件 Jar 时出错 - Error while trying to run executable Jar in cmd
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM