The ports the server uses is something you define in the server, not the application. So you can't do this by changing the WAR file.
Normally, servers only listen on one port (or range of ports). There are some (such as WebSphere) that allow you to define distinct virtual hosts which use differernt ports, but you can't deploy one EAR into two virtual hosts in the way you would like.
One way to do it is to put some sort of proxy in front of your web servers that redirects based on the context in the URL. Soemthing fairly basic like Apache HTTP server will do this.
I have Glassfish server to deploy my application EAR
Two WAR what we have is web services expossed with different context to control its accessiblity.
In Glassfish I have seen that we can create Virtual server and can deploy application to that virtual server
Is it possible to configure such virtual server for each WAR inside EAR?
Or Can anyone suggest any other way to package 2 WAR in signle EAR still having different Port configured?
I'm no Glassfish expert but I'd expect this can't be done. You certainly can't do it in any of the server I do know (so if a solution exists for Glassfish its not going to be portable). Configuration of the server itself is not normally something you can do from the JEE artifact.
subject: How to deploy different war on different port?