views:

497

answers:

1

How do I set up multiple entry points in an application client jar?

I am using Glassfish application server. I can grab the client using

 asadmin get-client-stubs --appname APPLICATION_NAME .

I currently can run the default mainclass that I have specified in the MANIFEST.MF. However, I want to be able to specify another mainclass at runtime.

ie

appclient -client MYJAR.jar -mainclass com.mystuff.Main1
and
appclient -client MYJAR.jar -mainclass com.mystuff.Main2

Both Main1 and Main2 have "public static void main" entry points.

If I specify a mainclass that is not in MANIFEST.MF, I get the following exception:

Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalArgumentException: Could not locate an embedded app client matching the main class name

Do I need to make any changes to have the appclient reference other mainclasses?

A: 

http://forums.java.net/jive/thread.jspa?threadID=65549&amp;tstart=0 <-- I reposted the same question here and someone gave the answer...

Hi.

The GlassFish app client container uses the -mainclass option to distinguish among multiple clients packaged into the same EAR so, at launch time, the user can choose which of those several clients that were packaged together to launch. As you've discovered, it does not allow the user to override the intent of the developer as to the main class to run within a given client.

You could do what you want using the alternate appclient syntax available in v3:

http://docs.sun.com/app/docs/doc/820-7701/appclient-1m?a=view

For v2 you could certainly write your single main class to accept an argument that specifies a class to be run and then load that class dynamically and invoke its main method.

-Tim

Tazzy531