从 Eclipse 中的工作应用程序导出后出现 ClassNotFoundException

发布于 2024-10-27 01:40:35 字数 1264 浏览 7 评论 0原文

因此,在将项目导出到可运行的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

逐鹿 2024-11-03 01:40:35

您的 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-click Project) and select Properties and then select Java Build Path and then Order and Export. Make sure the MySql library is exported.

椵侞 2024-11-03 01:40:35

好吧,你有一个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 the mysql file/jar paths.

慵挽 2024-11-03 01:40:35

请将 mysql jar 添加到工作区的项目类路径中。
以下是所需的 jar,请使用合适的 jar。

class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
mysql-connector-java-3.1.12-bin.jar
mysql-connector-java-3.1.12.jar
mysql-connector-java-5.0.7.jar
mysql-connector-java-3.1.14.jar
mysql-connector-java-5.1.5.jar
mysql-connector-java-5.0.4.jar
mysql-connector-java-5.0.5.jar
mysql-connector-java-5.1.4.jar
mysql-connector-java-5.1.3.jar
mysql-connector-java-3.1.11.jar
mysql-connector-java-3.1.13.jar
mysql-connector-java-5.1.1.jar
mysql-connector-java-5.0.2.jar
mysql-connector-java-5.0.8.jar
mysql-connector-java-5.0.3.jar
mysql-connector-java-5.1.2.jar
wildcat-core-2.0.1-embedded.jar
class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource [1216 bytes, jvm >= 1.2 ] 

mysql-connector-java-3.0.16-ga-bin.jar
class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource [1317 bytes, jvm >= 1.2 ] 

mysql-connector-java-5.1.6.jar
class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource [1216 bytes, jvm >= 1.2 ] 

mysql-connector-java-3.0.10-stable-bin.jar
mysql-connector-java-3.0.10.jar
mysql-connector-java-3.0.8-stable-bin.jar
mysql-connector-java-3.0.8.jar

class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource [735 bytes, jvm >= 1.1 ] 

mysql-connector-java-2.0.14-bin.jar
mysql-connector-java-2.0.14.jar

Please add mysql jars in project classpath of your workspace.
Below are required jar, please use appropriate jars.

class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
mysql-connector-java-3.1.12-bin.jar
mysql-connector-java-3.1.12.jar
mysql-connector-java-5.0.7.jar
mysql-connector-java-3.1.14.jar
mysql-connector-java-5.1.5.jar
mysql-connector-java-5.0.4.jar
mysql-connector-java-5.0.5.jar
mysql-connector-java-5.1.4.jar
mysql-connector-java-5.1.3.jar
mysql-connector-java-3.1.11.jar
mysql-connector-java-3.1.13.jar
mysql-connector-java-5.1.1.jar
mysql-connector-java-5.0.2.jar
mysql-connector-java-5.0.8.jar
mysql-connector-java-5.0.3.jar
mysql-connector-java-5.1.2.jar
wildcat-core-2.0.1-embedded.jar
class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource [1216 bytes, jvm >= 1.2 ] 

mysql-connector-java-3.0.16-ga-bin.jar
class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource [1317 bytes, jvm >= 1.2 ] 

mysql-connector-java-5.1.6.jar
class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource [1216 bytes, jvm >= 1.2 ] 

mysql-connector-java-3.0.10-stable-bin.jar
mysql-connector-java-3.0.10.jar
mysql-connector-java-3.0.8-stable-bin.jar
mysql-connector-java-3.0.8.jar

class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource [735 bytes, jvm >= 1.1 ] 

mysql-connector-java-2.0.14-bin.jar
mysql-connector-java-2.0.14.jar
〆一缕阳光ご 2024-11-03 01:40:35

您的可运行 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

撕心裂肺的伤痛 2024-11-03 01:40:35

使用
导出-> Java->可运行的 JAR 文件
反而
导出-> Java-> JAR 文件
在您的项目上(单击鼠标右键)。

Use
Export -> Java -> Runnable JAR File
instead
Export -> Java -> JAR File
on your project (right mouse click).

思念绕指尖 2024-11-03 01:40:35

将 jar 文件放在 /tomcat_dir/lib 下,它对我有用。

Place the jar file under /tomcat_dir/lib, it worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文