You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置含@字符参数的Maven测试-P命令无法运行求助

解决Maven命令行参数含@符号的执行问题

核心原因

@在bash、zsh这类常见shell里属于特殊字符,会被当作命令替换或邮件地址标识解析,导致参数被错误截断,出现你看到的内容变红、命令无法运行的情况。

可行解决方案

1. 转义@符号

在每个@前面加反斜杠\,让shell把@当作普通字符处理:

mvn test -P你的profile名 -DKEY=value:\@value -DKEY2=value2:n:\@value2

2. 用单引号包裹参数值

单引号在shell里会完全保留内部内容原样,不会解析任何特殊字符,直接把带@的参数值用单引号括起来:

mvn test -P你的profile名 -DKEY='value:@value' -DKEY2='value2:n:@value2'

3. 直接在Profile的properties中配置参数

如果不想在命令行处理特殊字符,把带@的参数直接写进pom.xml的profile里:

<profiles>
  <profile>
    <id>你的测试profile</id>
    <properties>
      <KEY>value:@value</KEY>
      <KEY2>value2:n:@value2</KEY2>
    </properties>
  </profile>
</profiles>

执行命令时只需激活profile即可:

mvn test -P你的测试profile

Windows CMD环境适配

如果用Windows的CMD,转义@需要用^符号:

mvn test -P你的profile名 -DKEY=value:^@value -DKEY2=value2:n:^@value2

或者用双引号包裹整个-D参数:

mvn test -P你的profile名 "-DKEY=value:@value" "-DKEY2=value2:n:@value2"

内容的提问来源于stack exchange,提问作者Nicolas Dumont

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 16:39:46