问题
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
回答1:
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.
回答2:
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.
回答3:
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
回答4:
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
回答5:
Use Export -> Java -> Runnable JAR File instead Export -> Java -> JAR File on your project (right mouse click).
回答6:
Place the jar file under /tomcat_dir/lib
, it worked for me.
来源:https://stackoverflow.com/questions/5416214/classnotfoundexception-after-exporting-from-working-application-in-eclipse