Maven在cmd中工作,但在powershell中不行 [英] Maven works in cmd but not powershell

查看:260
本文介绍了Maven在cmd中工作,但在powershell中不行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Maven在TFS Build Server上构建我的Java项目. TFS构建定义在工作流中使用invokeprocess. invokeprocess能够运行powershell脚本和命令批处理文件.

I want to build with maven my java projects on TFS Build Server. TFS Build Definition use invokeprocess in workflow. invokeprocess able to run powershell script and command batch file.

使用Windows命令提示符中的"mvn assembly:assembly -P prod"命令成功完成Maven构建.但是在powershell中没有成功. (我以远程用户身份连接到服务器并在Powershell ise上执行)(以普通用户或管理员身份)

Maven build successed with "mvn assembly:assembly -P prod" command in windows command prompt. But does not success in powershell. (I connected to server with remote and executed on powershell ise) (either as a regular user or as an administrator)

我在Windows 2012 Standart 64位计算机上安装了Maven 3.1.1和Java Dev Kit 6更新45.我们使用NTLM身份验证和代理.

I installed Maven 3.1.1 and Java Dev Kit 6 update 45 on Windows 2012 Standart 64-bit machine.We use NTLM authentication and proxy.

我定义了以下配置:

环境设置:

JAVA_HOME     C:\Program Files\Java\jdk1.6.0_45

M2            %M2_HOME%\bin

M2_HOME       C:\Program Files\Apache Software Foundation\apache-maven-3.1.1

路径:

  %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;%TFSPowerToolDir%;%BPADir%;%M2%;%JAVA_HOME%\bin

maven settings.xml:

maven settings.xml:

<settings>
<proxies>
<proxy>   
  <active>true</active>
  <protocol>http</protocol>
  <host>proxy.xxx.entp</host>
  <port>8080</port>
  <username>myuser</username>
  <password>mypassword</password>
  <nonProxyHosts>*.xxx.entp|localhost</nonProxyHosts>
</proxy>
</proxies>
</settings>

以下是我的powershell脚本:

The following is my powershell script:

# mvn clean install
# mvn assembly:assembly –P prod
Set-ExecutionPolicy Unrestricted -Force
$mvnArgs1 ="mvn assembly:assembly –P prod -Dmaven.test.skip=true".replace('-P','`-P').replace('-D','`-D')
Invoke-Expression $mvnArgs1

以下是powershell的输出:

The following is the output in powershell:

请单击输出Powershell的图像

maven如何在Powershell中工作?还是任何方式?

how to maven works in powershell? Or any way?

推荐答案

您不需要Invoke-Expression,请参阅我的博客文章:http://blogs.msdn.com/b/powershell/archive/2011/06/03/invoke-expression-considered-harmful.aspx

You don't need Invoke-Expression, see my blog post: http://blogs.msdn.com/b/powershell/archive/2011/06/03/invoke-expression-considered-harmful.aspx

在您的情况下,只需像在cmd中一样运行命令即可(事实证明您可能需要添加一些引号):

In your case, just run the command almost exactly like you would in cmd (it turns out you probably need to add some quotes):

mvn assembly:assembly -P prod "-Dmaven.test.skip=true"

这篇关于Maven在cmd中工作,但在powershell中不行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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