My application uses MySQL JDBC,I am trying to export JAR file using eclipse.
My question is how to include the MySQL driver so the JAR file can connect to server?
You should not include the MySQL driver in your jar. The driver is a separate jar, so you need to add it to your classpath when running your code.
If you are trying to create a single jar with all the dependencies, use either OneJar or UberJar to accomplish this.
If you are using ant, there is a simple ant task to do it and it supports to specify the main class and also the classpath in metainf
<jar id="files" jarfile="single.jar">
<zipfileset src="deped1.jar" includes="**/*.java **/*.class"/>
<zipfileset src="depend2.jar" includes="**/*.java **/*.class"/>
</jar>
Here is how to do that with Eclipse: How to create a jar with external libraries included in Eclipse?
Or you may use a tool like OneJar, http://one-jar.sourceforge.net/, to create a single runnable JAR file