Skip to main content

Multiple entry point (mainclass) for application client jar

3 replies [Last post]
tazzy531
Offline
Joined: 2007-05-21

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?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gorgeous65@msn.com

Hi,

If you are using an IDE such as netbeans, you can specify another class
as the main class. by:

In netbeans,

Right click Application\properties\Run

Under Client Module select your application client

then under

Main class of Client Information, specify the other
class then ok. Then deploy again.

If you are not using IDE, then you may want to call the
other class from the main class.

Sorry, if it does not help.

eve

--------------------------------------------------
From:
Sent: Wednesday, August 12, 2009 5:54 PM
To:
Subject: Multiple entry point (mainclass) for application client jar

> 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?
> [Message sent by forum member 'tazzy531' (tazzy531)]
>
> http://forums.java.net/jive/thread.jspa?messageID=360131
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

tjquinn
Offline
Joined: 2005-03-30

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
Offline
Joined: 2007-05-21

Thanks! That's EXACTLY what I was looking for.