[英]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
是极度手动编辑不友好的:
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.