[英]Why doesn't a runnable JAR exported from Eclipse work?
I have a project which runs fine from within Eclipse. 我有一个从Eclipse中运行良好的项目。 But when I export it to a runnable JAR with dependencies packed into it it won't run. 但是当我将它导出到可运行的JAR时,其中包含依赖项,它将无法运行。 The error, when running the JAR from console is: 从控制台运行JAR时的错误是:
EDIT (didnt run it with -jar before): 编辑(之前没有使用-jar运行它):
INFO: Loading XML bean definitions from class path resource [applicationContext-
framework.xml]
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOExc
eption parsing XML document from class path resource [applicationContext-framewo
rk.xml]; nested exception is java.io.FileNotFoundException: class path resource
[applicationContext-framework.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:349)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loa
dBeanDefinitions(AbstractXmlApplicationContext.java:113)
at org.springframework.context.support.AbstractXmlApplicationContext.loa
dBeanDefinitions(AbstractXmlApplicationContext.java:80)
at org.springframework.context.support.AbstractRefreshableApplicationCon
text.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtain
FreshBeanFactory(AbstractApplicationContext.java:422)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:352)
at org.springframework.context.support.ClassPathXmlApplicationContext.<i
nit>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<i
nit>(ClassPathXmlApplicationContext.java:93)
at com.horstmann.violet.UMLEditorApplication.getApplicationContext(UMLEd
itorApplication.java:111)
at com.horstmann.violet.UMLEditorApplication.<init>(UMLEditorApplication
.java:94)
at com.horstmann.violet.UMLEditorApplication.main(UMLEditorApplication.j
ava:84)
... 5 more
Caused by: java.io.FileNotFoundException: class path resource [applicationContex
t-framework.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPat
hResource.java:143)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:336)
... 20 more
but the file is in resources/
from the JAR-root. 但该文件位于resources/
来自JAR根目录。
What am I missing or doing wrong? 我错过了什么或做错了什么?
Try to click on the option “Package required libraries into generated JAR”. 尝试单击“将所需库打包到生成的JAR”选项。
A JAR file is a regular compressed archive. JAR文件是常规压缩存档。 Make sure that all the required libraries in your MANIFEST.MF file are present within the generated file. 确保MANIFEST.MF文件中的所有必需库都存在于生成的文件中。
Try to run the JAR from the command line - it will most likely display a useful error message. 尝试从命令行运行JAR - 它很可能会显示一条有用的错误消息。
There probably are some dependencies that eclipse doesn't know about or which aren't configured correctly within it, and are therefore missing from the JAR. 可能存在一些eclipse不知道的依赖关系,或者其中没有正确配置的依赖关系,因此JAR中缺少这些依赖关系。
In general, it's not a good idea to rely on IDE functionality to produce deliverables - it depends on too many hidden factors and can't be automated for a build server. 一般来说,依靠IDE功能来产生可交付成果并不是一个好主意 - 它取决于太多的隐藏因素,并且不能自动构建服务器。 Any project that's beyond the experimental/toy stage should have an automated build via Ant or Maven. 任何超出实验/玩具阶段的项目都应该通过Ant或Maven进行自动构建。
The message 消息
Could not find the main class: violet-0.21.2-SVN.jar. Program will exit.
indicates that you have gotten the Main-Class: MyPackage.MyClass
line wrong in the Manifest when packaging together the jar file. 表示在将jar文件打包在一起时,Manifest中的Main-Class: MyPackage.MyClass
行出错了。 You need to give the full name of the class with the main(String[] args) method. 您需要使用main(String [] args)方法提供类的全名。
See http://download.oracle.com/javase/tutorial/deployment/jar/appman.html for details. 有关详细信息,请参阅http://download.oracle.com/javase/tutorial/deployment/jar/appman.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.