简体   繁体   English

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

[英]ClassNotFoundException after exporting from working application in Eclipse

So I get this message after I have exported my project to a runnable jar. 因此,在将项目导出到可运行的jar后,我收到此消息。 I'm pretty clueless as to why this is since the application runs perfectly when I select "Run" in Eclipse. 我很清楚为什么这是因为当我在Eclipse中选择“Run”时应用程序运行完美 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

It looks like your MySql drivers haven't been exported. 看起来您的MySql驱动程序尚未导出。 To solve this go to Project Properties (right-click Project ) and select Properties and then select Java Build Path and then Order and Export . 要解决此问题,请转到Project Properties (右键单击Project )并选择Properties ,然后选择Java Build Path ,然后选择Order and Export Make sure the MySql library is exported. 确保导出MySql库。

在项目中使用Export - > Java - > Runnable JAR File而不是Export - > Java - > JAR File (单击鼠标右键)。

将jar文件放在/tomcat_dir/lib ,它对我/tomcat_dir/lib

Please add mysql jars in project classpath of your workspace. 请在工作区的项目类路径中添加mysql jar。 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

Well you have a java.lang.ClassNotFoundException . 那么你有一个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. 要检查它,只需右键单击您的Project -> Properties -> Java build path -> Libraries ,添加库或创建包含类的库并启用库的订单导出。

The error is shown because it is expecting a mysql data source. 显示错误是因为它需要一个mysql数据源。 You might not have provided one. 你可能没有提供。 Check with the mysql file/jar paths. 检查mysql file/jar路径。

Are the needed MySql jars in your runnable jar ? 你的runnable jar中需要的MySql jar吗?

Since it compiles and runs in Eclipse, the build path is likely ok.. 由于它在Eclipse中编译和运行,因此构建路径可能正常。

I think you also need to specify these jars via the Eclipse preference deploymentAssembly options. 我认为您还需要通过Eclipse首选项deploymentAssembly选项指定这些jar。 One way to check this is to export to a war file and check if the needed jars are in there by 检查这个的一种方法是导出到war文件并检查所需的罐子是否在那里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM