Java Eclipse 命令行参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19646719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse command line arguments
提问by
I understand how to run my application with command line arguments using the run configuration menu.
我了解如何使用运行配置菜单使用命令行参数运行我的应用程序。
The problem I have is that no matter what I update these command line arguments to, eclipse does not reflect these updates when I execute the code.
我遇到的问题是,无论我将这些命令行参数更新为什么,当我执行代码时,eclipse 都不会反映这些更新。
so far I have set the arguments to:
到目前为止,我已将参数设置为:
test1.txt test2.txt dfs
and this will print:
这将打印:
args[0] = test1.txt
args[1] = test2.txt
args[2] = dfs
but if I update the arguments and re-run it, the arguments won't update
但是如果我更新参数并重新运行它,参数将不会更新
How can I "reset" the arguments and re-run the application using the updated arguments.
如何“重置”参数并使用更新后的参数重新运行应用程序。
The above and below both function correctly and it was in fact eclipse that was causing me issues. The problem was resolved with a simple restart of eclipse.
上面和下面都正常运行,实际上是 eclipse 导致了我的问题。通过简单地重新启动 eclipse 就解决了这个问题。
Thanks all.
谢谢大家。
采纳答案by Little Child
- Click on Run-> Run Configurations
- Click on Argumentstab
- In Program Argumentssection , Enter your arguments.
- Click Apply
- 点击运行->运行配置
- 单击参数选项卡
- 在Program Arguments部分,输入您的参数。
- 点击应用
It is sure to work cause I tried it in mine right before I wrote this answer
它肯定会起作用,因为我在写这个答案之前就在我的身上试过了
回答by Tim
There is a situation (bug) where modifying the Run -> Run Configurations arguments does not work, since the actual run configuration being executed is actually hidden from you.
存在修改 Run -> Run Configurations 参数不起作用的情况(错误),因为正在执行的实际运行配置实际上对您隐藏。
So updating the visible one will not be reflected in your actual run.
因此更新可见的将不会反映在您的实际运行中。
Example:
例子:
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class EclipseRunConfigurationTest {
@Test
public void test() {
assertEquals("foo", System.getProperty("runProperty"));
}
}
- Run it - it will fail.
- Modify the run configuration using the method specified by Little Child. add "-DrunProperty=foo" VM parameter
- Run it again - it will pass
- Debug it, then switch to the debug view,
- RClick the Junit launch -> Edit Rerun EclipseRunConfigurationTest...
- Change the VM parameter to "-DrunProperty=bar"
- Apply and Debug - it will fail
- Open the Run/Debug manager again
- Note that 'Rerun EclipseRunConfigurationTest' is not listed.
- Note that the VM parameter is still "-DrunProperty=foo"
- No amount of changing it makes the slightest bit of difference.
- 运行它 - 它会失败。
- 使用 Little Child 指定的方法修改运行配置。添加“-DrunProperty=foo”虚拟机参数
- 再次运行它 - 它会通过
- 调试一下,然后切换到调试视图,
- R单击 Junit 启动 -> 编辑重新运行 EclipseRunConfigurationTest...
- 将 VM 参数更改为“-DrunProperty=bar”
- 应用和调试 - 它会失败
- 再次打开运行/调试管理器
- 请注意,未列出“重新运行 EclipseRunConfigurationTest”。
- 注意VM参数还是“-DrunProperty=foo”
- 再多的改变也不会有丝毫的不同。
I shall file a bug report.
我将提交错误报告。
The above was run on Eclipse Kepler running on Fedora 20.
以上是在 Fedora 20 上运行的 Eclipse Kepler 上运行的。
回答by Ashutosh Chopde
For Eclipse Neon Users
对于 Eclipse Neon 用户
Step 1: Click Run -> Run Configurations
步骤 1:单击运行 -> 运行配置
Step 2: Click on arguments Tab.
第 2 步:单击参数选项卡。
Step 3: insert required arguments in VM Arguments.
第 3 步:在 VM Arguments 中插入所需的参数。
Step 4: Click Apply
第 4 步:单击应用
Step 5: Click Run.
第五步:点击运行。
回答by Madhu
A small update in the solution given by Little Child above, to make it work with arguments having spaces in them. e.g. first argument - abc def second argument - ghi third argument - jkl mno pqrs
上面 Little Child 给出的解决方案的一个小更新,以使其与包含空格的参数一起工作。例如第一个参数 - abc def 第二个参数 - ghi 第三个参数 - jkl mno pqrs
In Program Arguments, give them like this using double quotes
在程序参数中,使用双引号给它们这样的
"abc def"
"ghi"
"jkl mno pqrs"
If you don't give spaces it will take abc as first argument and def as second argument and ghi as thrid argument and so on..
如果你不给空格,它将把 abc 作为第一个参数, def 作为第二个参数, ghi 作为第三个参数等等..