简体   繁体   English

为什么从Eclipse导出的可运行JAR不起作用?

[英]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.

相关问题 从Eclipse导出的可运行JAR文件似乎无法执行 - Exported runnable JAR file from Eclipse doesn't seem to execute 在运行时编译Java文件可在Eclipse上运行,但不能从导出的可运行jar文件中运行 - Compiling java file at runtime works on eclipse but doesn't work from an exported runnable jar file 项目在Eclipse中正常运行,但导出到可运行的jar时无法正常运行 - Project runs normal in Eclipse but doesn't when exported to a runnable jar 为什么Spring项目的导出的可运行JAR在另一个系统中不起作用? - Why doesn't an exported runnable JAR of a Spring project work in another system? 不会打开从 eclipse Mac OS 导出的可运行 jar - Won't open runnable jar exported from eclipse Mac OS 导出的可运行 jar 不包含来自 eclipse 2018-12 和 java 11 的依赖 jar。我们如何解决这个问题? - exported runnable jar doesn't contain dependency jars from eclipse 2018-12 with java 11. How do we solve this? 当导出可运行的jar程序不起作用时的Eclipse - Eclipse when export runnable jar program doesn't work Java打开文件-在Eclipse上有效,在可运行的JAR / exe中不起作用 - Java opening files - works from Eclipse, doesn't work in runnable JAR/exe 用eclipse导出的可运行jar不起作用,在eclipse中它仍然有效 - Runnable jar exported with eclipse isn't working, in eclipse it still works 导出的日食可运行.jar将无法运行 - Exported eclipse runnable .jar will not run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM