java - 如何复制 "ant run"以使用 appclient 执行 Glassfish ACC 客户端

标签 java jakarta-ee netbeans ant glassfish

如何运行appclient在 IDE 之外?而它seems possible to run stand-alone JNDI lookup apps from the CLIappclient ,它似乎不适用于 ACC 客户端。不过,这应该是可能的:

Running an Application Client

Using the appclient Script To run an application client, you can launch the ACC using the appclient script, whether or not Java Web Start is enabled.

GlassFish 服务器开源版 应用开发指南 4.0版本 开发 Java 客户端 10-15 第186页

步骤:

1.) created an @Remote interface as a Java SE library API

2.) created an Enterprise Application with an ejb module; add the interface API

3.) in the ejb module, implement the @Remote interface

4.) create an ACC app; add the interface API; add to the Enterprise Application

5.) insert the ejb from the IDE

6.) deploy the EAR and then run the ACC client from the IDE

改编自Creating and Running an Application Client on the GlassFish Server .

使用 ant 运行,从 CLI 中“ant run”:

-run:
     [java] 2

run:

BUILD SUCCESSFUL
Total time: 28 seconds
thufir@dur:~/NetBeansProjects/SingletonACC$ 

在本例中这是正确的输出。 (客户端每次运行,整数加一。)

我查看了 ant 文件,但无法破译“ant run”在这种情况下的作用:

   <!--
                =================
                EXECUTION SECTION
                =================
            -->
    <target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros,-run-pregfv3,-run" description="Run a main class." name="run"/>
    <target if="j2ee.appclient.tool.args" name="-run-pregfv3">
        <carproject:run-appclient-pregfv3/>
    </target>
    <target name="-run" unless="j2ee.appclient.tool.args">
        <carproject:run-appclient/>
    </target>
    <target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros,-run-single-pregfv3,-run-single" description="Run a single class." name="run-single"/>
    <target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros" name="-run-single" unless="j2ee.appclient.tool.args">
        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
        <carproject:run-appclient serverparams="${j2ee.appclient.tool.jvmoptions.class}${run.class}"/>
    </target>
    <target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros" if="j2ee.appclient.tool.args" name="-run-single-pregfv3">
        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
        <carproject:run-appclient-pregfv3/>
    </target>
    <target depends="init" name="-init-run-macros">
        <macrodef name="run-appclient" uri="http://www.netbeans.org/ns/car-project/1">
            <attribute default="${application.args.param}" name="args"/>
            <attribute default="${j2ee.appclient.tool.jvmoptions}${client.jar}" name="serverparams"/>
            <element name="customize" optional="true"/>
            <sequential>
                <java dir="${basedir}" fork="true" jar="${client.jar}">
                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
                    <jvmarg line="@{serverparams}"/>
                    <jvmarg line="${run.jvmargs.param}"/>
                    <arg line="@{args}"/>
                    <syspropertyset>
                        <propertyref prefix="run-sys-prop."/>
                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
                    </syspropertyset>
                    <env key="APPCPATH" path="${javac.classpath}"/>
                    <sysproperty key="java.system.class.loader" value="org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader"/>
                    <customize/>
                </java>
            </sequential>
        </macrodef>
        <macrodef name="run-appclient-pregfv3" uri="http://www.netbeans.org/ns/car-project/1">
            <element name="customize" optional="true"/>
            <sequential>
                <java classname="${j2ee.appclient.tool.mainclass}" fork="true">
                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
                    <jvmarg line="${j2ee.appclient.tool.jvmoptions}"/>
                    <jvmarg line="${run.jvmargs.param}"/>
                    <arg line="${j2ee.appclient.tool.args}"/>
                    <arg line="-client ${client.jar}"/>
                    <arg line="${application.args.param}"/>
                    <classpath>
                        <path path="${j2ee.platform.classpath}:${j2ee.appclient.tool.runtime}"/>
                    </classpath>
                    <syspropertyset>
                        <propertyref prefix="run-sys-prop."/>
                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
                    </syspropertyset>
                    <customize/>
                </java>
            </sequential>
        </macrodef>
    </target>
    <target if="j2ee.appclient.mainclass.args" name="-as-retrieve-option-workaround" unless="j2ee.clientName">
        <property name="client.jar" value="${dist.dir}/SingletonACCClient.jar"/>
        <sleep seconds="3"/>
        <copy failonerror="false" file="${wa.copy.client.jar.from}/SingletonACC/SingletonACCClient.jar" todir="${dist.dir}"/>
        <copy failonerror="false" flatten="true" todir="${dist.dir}/">
            <fileset dir="${wa.copy.client.jar.from}/SingletonACC" includes="**/SingletonACCClient.jar"/>
        </copy>
        <copy flatten="true" todir="${dist.dir}/SingletonACCClient">
            <fileset dir="${wa.copy.client.jar.from}/SingletonACC" includes="**/*.*ar"/>
        </copy>
        <copy failonerror="false" flatten="false" todir="${dist.dir}/SingletonACCClient">
            <fileset dir="${dist.dir}/gfdeploy/SingletonACC" includes="**/*.jar"/>
        </copy>
    </target>
    <target name="pre-run-deploy">
        <!-- Empty placeholder for easier customization. -->
        <!-- You can override this target in the ../build.xml file. -->
    </target>
    <target name="post-run-deploy">
        <!-- Empty placeholder for easier customization. -->
        <!-- You can override this target in the ../build.xml file. -->
    </target>
    <target name="-pre-nbmodule-run-deploy">
        <!-- Empty placeholder for easier customization. -->
        <!-- This target can be overriden by NetBeans modules. Don't override it directly, use -pre-run-deploy task instead. -->
    </target>
    <target name="-post-nbmodule-run-deploy">
        <!-- Empty placeholder for easier customization. -->
        <!-- This target can be overriden by NetBeans modules. Don't override it directly, use -post-run-deploy task instead. -->
    </target>
    <target name="-run-deploy-am">
        <!-- Task to deploy to the Access Manager runtime. -->
    </target>
    <target depends="init,compile,dist,pre-run-deploy,-pre-nbmodule-run-deploy,-run-deploy-nb,-init-deploy-ant,-deploy-ant,-run-deploy-am,-post-nbmodule-run-deploy,post-run-deploy,-do-update-breakpoints" name="run-deploy"/>
    <target if="netbeans.home" name="-run-deploy-nb">
        <nbdeploy clientUrlPart="${client.urlPart}" debugmode="false" forceRedeploy="${forceRedeploy}"/>
    </target>
    <target name="-init-deploy-ant" unless="netbeans.home">
        <property name="deploy.ant.archive" value="${dist.jar}"/>
        <property name="deploy.ant.resource.dir" value="${resource.dir}"/>
        <property name="deploy.ant.enabled" value="true"/>
    </target>
    <target depends="init,-run-undeploy-nb,-init-deploy-ant,-undeploy-ant" name="run-undeploy"/>
    <target if="netbeans.home" name="-run-undeploy-nb">
        <fail message="Undeploy is not supported from within the IDE"/>
    </target>
    <target depends="run-deploy,-init-display-browser,-display-browser-nb,-display-browser-cl" name="run-display-browser"/>
    <target if="do.display.browser" name="-init-display-browser">
        <condition property="do.display.browser.nb">
            <isset property="netbeans.home"/>
        </condition>
        <condition property="do.display.browser.cl">
            <and>
                <isset property="deploy.ant.enabled"/>
                <isset property="deploy.ant.client.url"/>
            </and>
        </condition>
    </target>
    <target if="do.display.browser.nb" name="-display-browser-nb">
        <nbbrowse url="${client.url}"/>
    </target>
    <target if="do.display.browser.cl" name="-get-browser" unless="browser">
        <condition property="browser" value="rundll32">
            <os family="windows"/>
        </condition>
        <condition else="" property="browser.args" value="url.dll,FileProtocolHandler">
            <os family="windows"/>
        </condition>
        <condition property="browser" value="/usr/bin/open">
            <os family="mac"/>
        </condition>
        <property environment="env"/>
        <condition property="browser" value="${env.BROWSER}">
            <isset property="env.BROWSER"/>
        </condition>
        <condition property="browser" value="/usr/bin/firefox">
            <available file="/usr/bin/firefox"/>
        </condition>
        <condition property="browser" value="/usr/local/firefox/firefox">
            <available file="/usr/local/firefox/firefox"/>
        </condition>
        <condition property="browser" value="/usr/bin/mozilla">
            <available file="/usr/bin/mozilla"/>
        </condition>
        <condition property="browser" value="/usr/local/mozilla/mozilla">
            <available file="/usr/local/mozilla/mozilla"/>
        </condition>
        <condition property="browser" value="/usr/sfw/lib/firefox/firefox">
            <available file="/usr/sfw/lib/firefox/firefox"/>
        </condition>
        <condition property="browser" value="/opt/csw/bin/firefox">
            <available file="/opt/csw/bin/firefox"/>
        </condition>
        <condition property="browser" value="/usr/sfw/lib/mozilla/mozilla">
            <available file="/usr/sfw/lib/mozilla/mozilla"/>
        </condition>
        <condition property="browser" value="/opt/csw/bin/mozilla">
            <available file="/opt/csw/bin/mozilla"/>
        </condition>
    </target>
    <target depends="-get-browser" if="do.display.browser.cl" name="-display-browser-cl">
        <fail unless="browser">
                    Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable.
                </fail>
        <property name="browse.url" value="${deploy.ant.client.url}${client.urlPart}"/>
        <echo>Launching ${browse.url}</echo>
        <exec executable="${browser}" spawn="true">
            <arg line="${browser.args} ${browse.url}"/>
        </exec>
    </target>
    <target depends="dist" name="verify">
        <nbverify file="${dist.jar}"/>
    </target>
    <target depends="init,compile-single" name="run-main">
        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
        <carproject:java classname="${run.class}"/>
    </target>
    <target depends="init" if="netbeans.home" name="-do-update-breakpoints">
        <carproject:nbjpdaappreloaded/>
    </target>

如何在 IDE 之外复制“ant run”

请注意SingletonAcc单独部署,尽管它也是 SingletonQueue 的一部分企业应用程序,其中还有 appclient .

thufir@dur:~/NetBeansProjects/SingletonACC$ 
thufir@dur:~/NetBeansProjects/SingletonACC$ /home/thufir/glassfish-4.1/glassfish/bin/asadmin list-applications
SingletonQueue  <ear, appclient, ejb>  
SingletonACC    <appclient>            
Command list-applications executed successfully.
thufir@dur:~/NetBeansProjects/SingletonACC$ 

最佳答案

您可以在 ant 中启用详细日志记录,以便您可以看到它实际执行的内容:

在 NetBeans 中,转到 Options -> Tools -> Java -> Ant 并设置 详细级别调试

看起来 ant 只是在 GlassFish 上部署了 appclient (EntAppClient.jar),然后使用一些类似于以下的参数运行文件 EntAppClientClient.jar(注意双 Client):

/java/jdk1.7.0/jre/bin/java.exe 
-Xbootclasspath/p:/NetBeans/enterprise/modules/ext/javaee6-endorsed/javax.annotation.jar;/NetBeans/enterprise/modules/ext/javaee6-endorsed/jaxb-api-osgi.jar;/NetBeans/enterprise/modules/ext/javaee6-endorsed/webservices-api-osgi.jar 
-Djava.endorsed.dirs=/glassfish410/glassfish/lib/endorsed;/glassfish410/glassfish/modules/endorsed 
-javaagent:/glassfish410/glassfish/lib/gf-client.jar=mode=acscript,arg=-configxml,arg=/glassfish410/glassfish/domains/domain1/config/glassfish-acc.xml,client=jar=dist/EntAppClientClient.jar 
-Djava.system.class.loader=org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader 
-jar /EntAppClient/dist/EntAppClientClient.jar

希望这有帮助:)

关于java - 如何复制 "ant run"以使用 appclient 执行 Glassfish ACC 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26033360/

相关文章:

java - 如何使用 jsoup 检查 HTML 元素的类型

java - Struts 中的 Controller

java - 获取java.util.Arrays$ArrayList的类

java - JSESSIONID 存储在哪里? (JavaEE)

java - 使用选择排序按字母顺序对数组进行排序

mysql - NetBeans 中的 "cannot be added because it does not have a primary key"错误

java - @Nonnull 和 Objects.requireNonNull 有什么区别

java - 选择并返回多个数组元素?等等 arrayName.get(1 到 3)

java - 如何实现加密的Android登录认证?

java - Netbeans 看不到引用库中的类