I have a project which runs fine from within Eclipse. But when I export it to a runnable JAR with dependencies packed into it it won't run. The error, when running the JAR from console is:
EDIT (didnt run it with -jar before):
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开发者_如何学Python 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.
What am I missing or doing wrong?
Try to click on the option “Package required libraries into generated JAR”.
A JAR file is a regular compressed archive. Make sure that all the required libraries in your MANIFEST.MF file are present within the generated file.
Try to run the JAR from the command line - it will most likely display a useful error message.
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.
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. Any project that's beyond the experimental/toy stage should have an automated build via Ant or 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. You need to give the full name of the class with the main(String[] args) method.
See http://download.oracle.com/javase/tutorial/deployment/jar/appman.html for details.
精彩评论