powershell运行java进程问题 [英] powershell run java process problem

查看:175
本文介绍了powershell运行java进程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Windows XP中的Powershell运行java进程。这是命令:

I'm trying to run a java process via Powershell in Windows XP. Here's the command:

java.exe -cp .;./common.jar -Dcontext=atest1 -Dresourcepath=. DW_Install

因此,类路径是。和.\common.jar(我认为java采用了错误的斜杠,对吧?)有两个环境变量,一个是atest1,另一个是。并且执行main的类是DW_Install(在默认包中)。

So, the classpath is . and .\common.jar (I think java takes the wrong slashes, right?) There are two environment variables, one "atest1" the other "." and the class to execute main on is DW_Install (in the default package).

此命令在cmd.exe中有效,但不是PS。这是怎么回事? PS解析CMD不执行此命令时做了什么(反之亦然)?

This command works in cmd.exe, but doesn't is PS. What's going on? What is PS doing while parsing this command that CMD doesn't do (or vice versa)?

Aaron

推荐答案

问题是PS出于某种原因以不同于cmd的方式解析 -Dresourcepath =。。有效的是

The problem is that PS for some reason parses -Dresourcepath=. differently than cmd. What works is

java -cp '.;.\common.jar' -Dcontext=atest1 "-Dresourcepath=." DW_Install

斜杠走向哪个方向并不重要,引用哪一个并不重要使用(')。但是,必须使用某种引号来转义类路径。一个好的测试看看PS解释器得到的是回应它。以下内容:

It doesn't matter which way the slash goes, and it doesn't matter which quotes one uses (' or "). The classpath must be escaped, however, with some kind of quotes. A good test to see what's getting by the PS interpreter is to echo it. The following:

echo java -cp '.;.\common.jar' -Dcontext=atest1 -Dresourcepath=. DW_Install

产生以下输出:

java
-cp
.;.\common.jar
-Dcontext=etaste1
-Dresourcepath=
.
DW_Install

(注意资源路径和resourcepath的值不在同一行。)输出到

(Notice the resourcepath and the value of resourcepath are not on the same line.) Whereas the output to

echo java -cp '.;.\common.jar' -Dcontext=atest1 '-Dresourcepath=.' DW_Install

产生以下输出:

java
-cp
.;.\common.jar
-Dcontext=etaste1
-Dresourcepath=.
DW_Install

这更符合我们的喜好。

虽然我希望你们没有这个,但我希望这篇文章可以帮助那些必须在Windows机器上部署java项目的人(即使他们不会在任何其他平台上运行)。

Although I wish this upon none of you, I hope that this post helps those of you that must deploy java projects on Windows machines (even though they will not run on any other platform ever).

这篇关于powershell运行java进程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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