从 Eclipse 中的工作应用程序导出后出现 ClassNotFoundException
因此,在将项目导出到可运行的 jar 后,我收到此消息。我很不明白为什么会这样,因为当我在 Eclipse 中选择“运行”时,应用程序运行完美。我已经尝试过提取和打包可靠的库,但没有雪茄。
有人知道该怎么办吗?
Exception in thread "main" java.lang.NoClassDefFoundError: com/mysql/jdbc/jdbc2/optional/MysqlDataSource
at jp.kddi.geonames.GeoNames.getConnectionWithDataSource(GeoNames.java:55)
at jp.kddi.geonames.GeoNames.setFromGN(GeoNames.java:155)
at jp.kddi.twittercrawler.Attributes.setCoordinatesGeonames(Attributes.java:297)
at jp.kddi.twittercrawler.Attributes.setCoordinatesJSON(Attributes.java:280)
at jp.kddi.twittercrawler.Attributes.SetAll(Attributes.java:42)
at jp.kddi.twittercrawler.TweetList.makeList(TweetList.java:25)
at jp.kddi.twittercrawler.TweetCloud.main(TweetCloud.java:45)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 7 more
So I get this message after I have exported my project to a runnable jar. I'm pretty clueless as to why this is since the application runs perfectly when I select "Run" in Eclipse. I've tried both extract and package dependable libraries but no cigar.
Anyone know what to do?
Exception in thread "main" java.lang.NoClassDefFoundError: com/mysql/jdbc/jdbc2/optional/MysqlDataSource
at jp.kddi.geonames.GeoNames.getConnectionWithDataSource(GeoNames.java:55)
at jp.kddi.geonames.GeoNames.setFromGN(GeoNames.java:155)
at jp.kddi.twittercrawler.Attributes.setCoordinatesGeonames(Attributes.java:297)
at jp.kddi.twittercrawler.Attributes.setCoordinatesJSON(Attributes.java:280)
at jp.kddi.twittercrawler.Attributes.SetAll(Attributes.java:42)
at jp.kddi.twittercrawler.TweetList.makeList(TweetList.java:25)
at jp.kddi.twittercrawler.TweetCloud.main(TweetCloud.java:45)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 7 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的 MySql 驱动程序似乎尚未导出。要解决此问题,请转到
Project Properties
(右键单击Project
)并选择Properties
,然后选择Java Build Path
然后订购并导出
。确保 MySql 库已导出。It looks like your MySql drivers haven't been exported. To solve this go to
Project Properties
(right-clickProject
) and selectProperties
and then selectJava Build Path
and thenOrder and Export
. Make sure the MySql library is exported.好吧,你有一个
java.lang.ClassNotFoundException
。这意味着应用程序运行时缺少一个类。您应该检查是否已将所有库添加到构建路径中。要检查它,只需右键单击您的
Project ->属性-> Java构建路径->库
,添加您的库或创建一个包含您的类的库,并为您的库启用订单导出。显示错误是因为它需要
mysql
数据源。您可能没有提供。检查mysql file/jar
路径。Well you have a
java.lang.ClassNotFoundException
. That means a class is missing in the application runtime. You should check whether you have added all your libs to the build path.For checking it, just right click on your
Project -> Properties -> Java build path -> Libraries
, add your libraries or create one containing your classes and enable order export for your libraries.The error is shown because it is expecting a
mysql
data source. You might not have provided one. Check with themysql file/jar
paths.请将 mysql jar 添加到工作区的项目类路径中。
以下是所需的 jar,请使用合适的 jar。
Please add mysql jars in project classpath of your workspace.
Below are required jar, please use appropriate jars.
您的可运行 jar 中有所需的 MySql jar 吗?
由于它在 Eclipse 中编译并运行,因此构建路径可能没问题。
我认为您还需要通过 Eclipse 首选项DeploymentAssembly 选项指定这些 jar。检查这一点的一种方法是导出到一个 war 文件并检查所需的 jar 是否在其中
Are the needed MySql jars in your runnable jar ?
Since it compiles and runs in Eclipse, the build path is likely ok..
I think you also need to specify these jars via the Eclipse preference deploymentAssembly options. One way to check this is to export to a war file and check if the needed jars are in there by
使用
导出-> Java->可运行的 JAR 文件
反而
导出-> Java-> JAR 文件
在您的项目上(单击鼠标右键)。
Use
Export -> Java -> Runnable JAR File
instead
Export -> Java -> JAR File
on your project (right mouse click).
将 jar 文件放在
/tomcat_dir/lib
下,它对我有用。Place the jar file under
/tomcat_dir/lib
, it worked for me.