gpt4 book ai didi

java - 应用程序客户端 jar 的多个入口点(主类)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:13 25 4
gpt4 key购买 nike

如何在应用程序客户端 jar 中设置多个入口点?

我正在使用 Glassfish 应用服务器。我可以使用

 asadmin get-client-stubs --appname APPLICATION_NAME .

我目前可以运行我在 MANIFEST.MF 中指定的默认主类。但是,我希望能够在运行时指定另一个主类。

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

Main1 和 Main2 都有“public static void main”入口点。

如果我指定一个不在 MANIFEST.MF 中的主类,我会得到以下异常:

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

我是否需要进行任何更改才能让 appclient 引用其他主类?

最佳答案

http://forums.java.net/jive/thread.jspa?threadID=65549&tstart=0 <-- 我在这里重新发布了同样的问题,有人给出了答案......

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

关于java - 应用程序客户端 jar 的多个入口点(主类),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1266791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com