I want to run 2 different main-classes from the same JAR. Is it
possible?
Sure, you can do that, but[1]
One way is as described ny Thomsa Kellerer, to
launch two different mains from the one Jar by
invoking the class from the command line.
Another, more user-friendly way to deploy the
applications is using Webstart/JWS, which would simply
require you to specify a different main in each JNLP
descriptor.
*Note the jar file/s for JWS would need to be signed if
you intend the application/s to gain the 'full priviliges'
usually given to an app. launched from the command line.*
The point is that both main-classes use the same common classes,
[1] ..but, as Thomas Hawtin suggested, it may
not make sense to deploy the mains and core classes
in the same jar. Instead consider breaking it into
the 'common library' jar, with each main class and
it's own unique classes in a second (third, fourth..)
jar.
Webstart/JWS can handle that as well, and will only
deliver the library application once, even if it is
used for 10 different applications (or Webstarted
applets).
..so it
seems better that all classes will reside in the same 1 JAR file.
Not with the JWS option..