如何将属性从 Powershell 传递给 jar? [英] How to pass Properties to jar from Powershell?

查看:23
本文介绍了如何将属性从 Powershell 传递给 jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Powershell-1.0 来满足命令行需求,而不是 cmd.exe.不幸的是,在使用 Java 时仍有一些注意事项.我需要将一个属性传递给一个 jar,就像这样:

I've been using Powershell-1.0 for command line needs for a while, instead of cmd.exe. Unfortunately, there are still some caveats when using Java. I need to pass a property to a jar, like that:

java -jar -Duser.language=en any.jar

此行在 cmd.exe 中工作正常,但在 Powershell 中无法正常工作,因为它会搜索另一个 jar:

This line works fine in cmd.exe, but not in Powershell as it searches for another jar:

无法访问 jarfile user.language=en

Unable to access jarfile user.language=en

使用引号无济于事.

它在 Powershell-1.0 中是否可行,或者我是否遗漏了 Java 中的某些内容?

Is it doable in Powershell-1.0, or do I miss something in Java?

推荐答案

看看我对此的回答 问题.请注意如何使用 echoargs.exe 来诊断此类问题.最有可能的解决方法是引用参数,例如:

Take a look at my answer to this question. Note how you can use echoargs.exe to diagnose these sort of problems. Most likely the fix would be to quote the parameter e.g.:

java -jar "-Duser.language=en" any.jar

您可以使用 echoargs 进行测试(来自 PowerShell Community Extensions):

You can test that using echoargs (from PowerShell Community Extensions):

echoargs -jar "-Duser.language=en" any.jar
Arg 0 is <-jar>
Arg 1 is <-Duser.language=en>
Arg 2 is <any.jar>

这篇关于如何将属性从 Powershell 传递给 jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆