Well, the answer depends on how you are going to create your runnable JAR file. As you are using eclipse, I assume you simply exported your project.
First ... When exporting, always select Runnable JAR file as the export type when having a - hmm - runnable program (with a main class), as this will create the manifest file with all appropriate entries. The most important entries are - by the way - the Main-Class and the Class-Path entry.
The export wizard has a handful of options with which you can control what and how is really exported. This will also have an effect on the manifest file, of course. Look at this screenshot:
You see the three options regarding library handling? Let me explain:
- Extract required libraries into generated JAR
The easiest option for small programs. This will create one JAR file containing all classes (and other resources) of your libraries. In fact, the content of all libraries is extracted and put into the exported JAR. This is called a Fat JAR.
- Package required libraries into generated JAR
This is some other form of a fat JAR. All your libraries are put as is into the generated JAR file. That is, your generated JAR contains your classes and resources and all library JAR files. Starting your own main class now doesn't work, as JARs in JARs cannot be read correctly. Therefore eclipse creates a Main-Class entry in the manifest file pointing to the class org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
. This main class knows how to load the contents of all packaged libraries, and it starts your own main class.
- Copy required libraries into a sub-folder next to generated JAR
This is the - I would say - most professional option. This is preferrable for larger projects. The generated JAR file will now only contain your project's classes and resource. Additionally a sub-folder (next to your JAR) will be created that contains all your library JARS. The manifest file of your JAR now must contain a Class-Path entry that lists all those libraries. This is what Jon Skeet asked for in his comment. The export wizard will create this manifest entry correctly.
Regardless of what export option you select, you are then able to start your program with a simple
java -jar your-jar-file