【问题标题】:How do you specify the server information used by the tomcat7-maven-plugin on the command line?如何在命令行指定tomcat7-maven-plugin使用的服务器信息?
【发布时间】:2018-02-20 21:43:58
【问题描述】:

我正在使用 tomcat7-maven-plugin 将我的应用程序部署到 Tomcat。在我的 pom.xml 中,我目前有以下信息

 <plugin>
   <groupId>org.apache.tomcat.maven</groupId>
   <artifactId>tomcat7-maven-plugin</artifactId>
   <version>2.2</version>
   <configuration>
      <server>test</server>
      <path>/api</path>
      <update>true</update>
      <url>http://XXX.XXX.XX.XX:8080/manager/text</url>
   </configuration>
 </plugin>

在 ~/.m2/settings.xml 我有以下内容

<settings>
  <servers>
    <server>
      <id>test</id>
      <username>*******</username>
      <password>*******</password>
    </server>

    <server>
      <id>production</id>
      <username>*********</username>
      <password>*********</password>
    </server>
  </servers>
</settings>

我希望能够将通过 ID 选择服务器作为我的命令行的一部分,例如

mvn tomcat7:redeploy -Dserver=production

并使用来自 settings.xml 文件的适当配置信息。除了选择特定的用户名和密码进行部署外,这还意味着将 URL 从 pom.xml 移到单独的位置。

This post 谈到将服务器 URL 存储在 POM 之外,似乎表明有一种方法可以使用一些属性文件来完成这部分,但没有扩展这些文件的位置,也没有说明如何指定它们在命令行上。

是否可以做我正在寻找的事情?还是每次我想选择不同的服务器部署到时都在编辑 pom.xml 文件?

【问题讨论】:

    标签: maven tomcat deployment


    【解决方案1】:

    将服务器 ID(和凭据)保存在 ~/.m2/settings.xml 中的另一种方法是将服务器 url 设置为 pom.xml 中的参数:

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat7-maven-plugin</artifactId>
         <version>2.2</version>
         <configuration>
             <url>${deploy.server}</url>             
         </configuration>
    <plugin>
    

    然后,当您运行部署目标时,您指定要使用的服务器的 url:

    mvn tomcat7:deploy -Ddeploy.server="http://prod.example.com:8080/manager/text" -Dtomcat.username=sfalken -Dtomcat.password=JOSHUA
    

    【讨论】:

    • 不将凭据存储在 pom.xml 中的好解决方案(可能会在版本控制中检查)
    猜你喜欢
    • 2012-07-01
    • 1970-01-01
    • 2014-01-29
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 2021-07-26
    相关资源
    最近更新 更多