This has been asked before but I cannot find the answer I need.
1) Using Class.forName("com.mysql.java.Driver")
in the eclipse IDE all works well. I load the correct jar (mysql-connector-java-5.1.20-bin.jar), no exception.
When I create a jar for my app a1.jar and double click the jar, I get the ClassnotFoundException
.
I created a .bat file in Windows XP with
java -classpath c:\temp\mysql-connector-java-5.1.20-bin.jar -jar c:\temp\a1.jar
the app statrs with the same exception.
Furthermore using System.getProperty ("java.class.path")
shows c:\temp\a1.jar
whilst in the IDE I can see several directories
If you are executing a file using -jar
, then any external classpath (either provided on the commandline or the environment) is ignored. It only looks to the Class-path:
entry in the META-INF/MANIFEST.MF
file. If the MySQL jar isn't specified there, it won't load it.