gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 03:56:00 24 4
gpt4 key购买 nike

全部,

我有一个 NetBeans 平台项目(只是一个我用 NetBeans 编写的项目,而是一个使用 rich client framework provided by NetBeans 的项目)。我可以通过 ant run 运行项目命令。现在,我想传递一个参数,该参数将通过 ant 起作用。可通过 System.getProperty 访问方法。

我知道我需要使用 <sysproperty>节点实际将键/值对注入(inject)运行时环境,但对于我来说,我无法弄清楚如何让它与 NetBeans 为您创建的复杂构建树一起工作(build.xml 取决于 build-impl.xml)。 xml,它又依赖于 ${harness.dir}/suite.xml,而后者又依赖于 ${harness.dir}/run.xml)

simplest example我发现是

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

但问题是我的 xml 文件都没有易于访问的 <java>节点那样。我想我已经设法追踪执行流程到实际调用某些东西的地方(在 ${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 文件以注入(inject)只影响我的一个项目而不影响所有项目的属性,这似乎是一件非常错误的事情。那么,确保我传递给 ant run 的命令行属性最终出现在 NetBeans 平台项目中的正确方法是什么?

最佳答案

在您的 RCP 应用程序的分发中有一个文件夹 etc 并且该文件夹中有文件 yourapp.conf 我认为您正在寻找答案。例如来 self 的一个 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=

关于java - Ant、NetBeans 平台项目 - 如何通过 System.getProperties 传递命令行参数和访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4938650/

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