If we go through the different points you mentioned:
I am working a problem where multiple applications need to share classes loaded by each other: put the classes in a common classloader at the server level, and remove them from the WARs WEB-INF/libs to avoid that WAR classes hide server classes. For example in the case of Tomcat put the jars in $TOMCAT_HOME/lib
.
why this not a good idea: This is usually not a good idea and we should only put at the server level the minimum amount of classes needed, to avoid problems due to static variables (linked to the class) to be unintentionally shared accross applications, increased possiblity of class cast exceptions, etc.
So I have started by creating a separate application and putting all the common libraries in it: This won't work as you expect, the classes in one WAR application's WEB-INF/lib are isolated and not visible in classes in another WAR. So creating a separate application is not the way to achieve this, but installing the classes at a classloader at the server level.
I am trying to find out its possible to load all classes under WEB-INF/lib/.jar as soon the war is deployed:* This is not foreseen in servlet containers, see this answer for a way to do this using Java code. The reason this feature is not available is that the JVM loads the classes lazily when they are needed by other classes, and no upfront loading is done in order to save memory.
The moment when the loading of the classes occurs is best left to the inner workings of the JVM, where many optimizations are in place to load classes in the most efficient way and avoid perm gen issues.
If this does not answer the questions can you let us know what your use case is for needing to load classes upfront, we might be able to provide some alternative for what you are trying to implement - like increasing timeouts for initial requests, etc.