I have not write a simple (Swing) java application since a long time, and I have a doubt !
The application use three external jar files.
Can I package the application so it is only include in ONE jar file (easier to deploy)?
I disagree. Yes, you can package jar files inside another jar file, but the standard class loader will not look into any of those jar files when it is trying to find a class to load.
You could write your own classloader to load classes from those jars but it is probably more effort than just redistributing all the jar files separately.
I have a vague recollection that there may be a 3rd party classloader available that will allow you to do this. Try searching these forums for the many times this question has been asked before.
Correct. However, you can package them into one sub folder, then include that sub folder in the class path:
You can of course also skip the sub folder; your class path will then be as K. Tsang mentioned.
Olivier Scalbert wrote:As I will not be able to start the application like this:
java -jar application.jar
without playing with class loader, I will forget this approach.
You will need to distribute the jar files separately whichever way you choose to launch your program. Using the -jar option means you can specify the classpath in the manifest file of your application jar and don't need to specify it on the command line.
Olivier Scalbert wrote:By the way, why the standard class loader does not look into the included jar files ?
Is there a good reason ?
Don't know I'm afraid. Probably just to avoid making the class loading process too complicated.
Olivier Scalbert wrote:Finally what is the purpose of the "Class_path" entry ?
When you use the -jar option, the JVM uses the Class_path" entry to find any classes it needs to load.
IF you don't use the -jar option then you need to specify your classpath on the command line with the -cp option.