如何使用应用程序客户端复制"ant run"以执行 Glassfish ACC 客户端



如何在IDE之外运行appclient?虽然使用appclient从CLI运行独立的JNDI查找应用程序似乎是可能的,但它似乎不适用于ACC客户端。然而,这应该是可能的:

运行应用程序客户端

使用appclient脚本要运行应用程序客户端,您可以使用appclient脚本启动ACC,无论是否启用Java Web Start。

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

步骤:

1.)创建了一个@Remote接口作为Java SE库API

2.)创建了一个带有ejb模块的企业应用程序;添加接口API

3.)在ejb模块中,实现@Remote接口

4.)创建ACC应用程序;增加接口API;添加到企业应用程序

5.)从IDE 插入ejb

6.)部署EAR,然后从IDE 运行ACC客户端

这是根据在GlassFish服务器上创建和运行应用程序客户端改编的。

使用ant运行,从CLI:"ant run"

-run:
     [java] 2
run:
BUILD SUCCESSFUL
Total time: 28 seconds
thufir@dur:~/NetBeansProjects/SingletonACC$ 

这在这种情况下是正确的输出。(每次客户端运行时,整数都会增加一。)

我浏览了蚂蚁的文件,但无法解读"蚂蚁运行"在这种情况下的作用:

   <!--
                =================
                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),然后运行文件EntAppClient.jar(注意双客户端),其中包含一些类似于以下的参数:

/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

希望这有帮助:)

相关内容

  • 没有找到相关文章

最新更新