Ant、NetBeans 平台项目 - 如何传递命令行参数并通过 System.getProperties 进行访问?

发布于 2024-10-16 15:27:32 字数 3517 浏览 3 评论 0原文

总之,

我有一个 NetBeans 平台项目(不仅仅是我在 NetBeans 中编写的一个项目,而是一个使用 NetBeans 提供的富客户端框架)。我可以通过 ant run 命令运行该项目。现在,我想传递一个参数,该参数将通过 ant 工作,以便通过 System.getProperty 方法进行访问。

我知道我需要使用 节点将键/值对实际注入到运行时环境中,但我一生都不知道如何让它工作NetBeans 为您创建的复杂构建树(build.xml 依赖于 build-impl.xml,而后者又依赖于 ${harness.dir}/suite.xml,而后者又依赖于 ${harness.dir}/run .xml)

我发现的最简单的示例

<target name="run" depends="compile">
    <java classname="prop"
          fork="true">
      <sysproperty key="test.property"
                   value="blue"
                   />
    </java>
  </target>

但问题是我的 xml 文件都没有这样易于访问的 节点。我想我已经设法跟踪执行流程到实际调用某些内容的位置(在 ${harness.dir}/run.xml 中),

<target name="run" depends="-prepare-as-app,-prepare-as-platform">
        <touch file="${cluster}/.lastModified"/> <!-- #138427 -->
        <property name="run.args" value=""/>
        <property name="run.args.ide" value=""/>
        <property name="run.args.extra" value=""/>
        <condition property="run.args.mac" value="-J-Xdock:name=${app.name}" else="">
            <os family="mac"/>
        </condition>
        <exec osfamily="windows" executable="${run.exe}" failonerror="no" resultproperty="result.prop">
            <arg value="--jdkhome"/>
            <arg file="${run.jdkhome}"/>
            <arg line="${run.args.common}"/>
            <arg line="${run.args.prepared}"/>
            <arg line="${run.args}"/>
            <arg line="${run.args.ide}"/>
            <arg line="${run.args.extra}"/>
        </exec>
        <exec osfamily="unix" dir="." executable="sh"
        failonerror="no" resultproperty="result.prop">
            <arg value="${run.sh}"/>
            <arg value="--jdkhome"/>
            <arg file="${run.jdkhome}"/>
            <arg line="${run.args.common}"/>
            <arg line="${run.args.prepared}"/>
            <arg line="${run.args}"/>
            <arg line="${run.args.ide}"/>
            <arg line="${run.args.extra}"/>
            <arg line="${run.args.mac}"/>
        </exec>
        <fail>
The application is already running within the test user directory.
You must shut it down before trying to run it again.
            <condition>
                <and>
                    <isset property="result.prop" />
                    <or>
                        <!-- unknown option exit code as returned from IDE by org.netbeans.api.sendopts.CommandLine -->
                        <equals arg1="${result.prop}" arg2="50346" />
                        <!-- unknown option exit code as returned from platform app by org.netbeans.CLIHandler -->
                        <equals arg1="${result.prop}" arg2="2" />
                    </or>
                </and>
            </condition>
        </fail>
    </target>

如您所见,没有 < java> 节点,我可以在其下放置自定义 sysproperty。此外,必须使用harness xml 文件来注入仅影响我的一个项目而不是所有项目的属性,这似乎是一件非常错误的事情。那么,确保传递给 ant run 的命令行属性最终出现在 NetBeans 平台项目中的正确方法是什么?

All,

I have a NetBeans Platform project (not just a project I wrote in NetBeans, but one using the rich client framework provided by NetBeans). I can run the project via an ant run command. Now, I want to pass in an argument that will work its way through ant to be accessible via the System.getProperty method.

I understand that I need to use a <sysproperty> node to actually inject the key/value pair into the runtime environment, but for the life of me I cannot figure out how to get this to work with the convoluted build tree that NetBeans creates for you (build.xml depends on build-impl.xml, which in turn depends on ${harness.dir}/suite.xml, which in turn depends on ${harness.dir}/run.xml)

The simplest example I've found is

<target name="run" depends="compile">
    <java classname="prop"
          fork="true">
      <sysproperty key="test.property"
                   value="blue"
                   />
    </java>
  </target>

but the problem is that none of my xml files have an easily accessible <java> node like that. I think I've managed to trace the execution flow to where something is actually invoked (in ${harness.dir}/run.xml)

<target name="run" depends="-prepare-as-app,-prepare-as-platform">
        <touch file="${cluster}/.lastModified"/> <!-- #138427 -->
        <property name="run.args" value=""/>
        <property name="run.args.ide" value=""/>
        <property name="run.args.extra" value=""/>
        <condition property="run.args.mac" value="-J-Xdock:name=${app.name}" else="">
            <os family="mac"/>
        </condition>
        <exec osfamily="windows" executable="${run.exe}" failonerror="no" resultproperty="result.prop">
            <arg value="--jdkhome"/>
            <arg file="${run.jdkhome}"/>
            <arg line="${run.args.common}"/>
            <arg line="${run.args.prepared}"/>
            <arg line="${run.args}"/>
            <arg line="${run.args.ide}"/>
            <arg line="${run.args.extra}"/>
        </exec>
        <exec osfamily="unix" dir="." executable="sh"
        failonerror="no" resultproperty="result.prop">
            <arg value="${run.sh}"/>
            <arg value="--jdkhome"/>
            <arg file="${run.jdkhome}"/>
            <arg line="${run.args.common}"/>
            <arg line="${run.args.prepared}"/>
            <arg line="${run.args}"/>
            <arg line="${run.args.ide}"/>
            <arg line="${run.args.extra}"/>
            <arg line="${run.args.mac}"/>
        </exec>
        <fail>
The application is already running within the test user directory.
You must shut it down before trying to run it again.
            <condition>
                <and>
                    <isset property="result.prop" />
                    <or>
                        <!-- unknown option exit code as returned from IDE by org.netbeans.api.sendopts.CommandLine -->
                        <equals arg1="${result.prop}" arg2="50346" />
                        <!-- unknown option exit code as returned from platform app by org.netbeans.CLIHandler -->
                        <equals arg1="${result.prop}" arg2="2" />
                    </or>
                </and>
            </condition>
        </fail>
    </target>

As you can see, there is no <java> node underneath which I can put my custom sysproperty. Furthermore, it seems like a very wrong thing to do to have to muck around with harness xml files to inject a property that only affects one of my projects, not all of them. So what's the correct way to ensure that a command line property I pass to ant run ends up within a NetBeans Platform project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城半夏 2024-10-23 15:27:32

在您的 RCP 应用程序的发行版中有一个文件夹 etc ,该文件夹中有文件 yourapp.conf 我认为您正在寻找答案。例如,来自我的一个 NB RCP 应用程序:

# ${HOME} will be replaced by user home directory according to platform
default_userdir="${HOME}/.${APPNAME}/dev"
default_mac_userdir="${HOME}/Library/Application Support/${APPNAME}/dev"

# options used by the launcher by default, can be overridden by explicit
# command line switches
default_options="--laf Metal --branding xmled -J-Xms24m -J-Xmx64m"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea

# default location of JDK/JRE, can be overridden by using --jdkhome <dir> switch
#jdkhome="/path/to/jdk"

# clusters' paths separated by path.separator (semicolon on Windows, colon on Unices)
#extra_clusters=

There is a folder etc in the distribution of your RCP app and in that folder is file yourapp.conf i think there is an answer you seek. For example from one of mine NB RCP app:

# ${HOME} will be replaced by user home directory according to platform
default_userdir="${HOME}/.${APPNAME}/dev"
default_mac_userdir="${HOME}/Library/Application Support/${APPNAME}/dev"

# options used by the launcher by default, can be overridden by explicit
# command line switches
default_options="--laf Metal --branding xmled -J-Xms24m -J-Xmx64m"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea

# default location of JDK/JRE, can be overridden by using --jdkhome <dir> switch
#jdkhome="/path/to/jdk"

# clusters' paths separated by path.separator (semicolon on Windows, colon on Unices)
#extra_clusters=
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文