java - 添加有关新主机的信息

标签 java maven

我对其他真正有才华的人编写的项目有疑问。

我尝试使用 Maven 将项目部署到远程主机

user@user:~/workspace/pip$ mvn -P production, partner clean install -Dmaven.test.skip=true 

它构建成功,没有任何错误和警告。

“partner”是服务器 machine.partner.rmm.com 的简称。

但是当我想部署到新服务器partner-test.rmm.com

user@user:~/workspace/pip$ mvn -P production, partner-test clean install -Dmaven.test.skip=true 

......
[INFO] Reactor Summary:
[INFO] 
[INFO] pip_part1 .................................... SUCCESS [4.574s]
[INFO] pip-part2 .................................... SUCCESS [3.677s]
[INFO] pip-part3 .................................... SUCCESS [5.178s]
[INFO] pip-part4 .................................... SUCCESS [3.857s]
[INFO] pip-part5 .................................... SUCCESS [0.134s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.861s
[INFO] Finished at: Thu Dec 04 11:46:24 MSK 2014
[INFO] Final Memory: 33M/285M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "partner-test" could not be activated because it does not exist.

它构建了,但写道合作伙伴测试不存在,并且符合逻辑,因此我没有在任何地方添加有关合作伙伴测试是什么的信息。但是当我尝试使用全名部署时也有同样的情况

user@user:~/workspace/pip$ mvn -P production, partner-test.rmm.com clean install -Dmaven.test.skip=true 

pom.xml

pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.rmm.pipproject</groupId>
<artifactId>pip</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>pip-part1</module>
    <module>pip-part2</module>
    <module>pip-part3</module>
    <module>pip-part4</module>
</modules>

我使用Eclipse Java IDE(版本:Kepler),Ubuntu 14.04,maven 1.7.0_65,ant 1.9.3。

我应该做什么?在哪里添加partner-test的信息?

p.s.:我知道我的知识还不够,但我试图了解更多,我希望你能帮助我。我将不胜感激任何建议!

<小时/>

我想添加一些通知。

<小时/>

嗯,我说过我的目标是使用 Maven 和 Ant 将项目部署到远程主机。 根据andih的建议(非常感谢他!!!)我将 profile-tag 添加到项目 pip 的 pom.xml 中。它对我有帮助真是太棒了。结果是在以下命令后建立了连接。

user@user:~/workspace/pip$ mvn -P production, partner clean install -Dmaven.test.skip=true 
user@user:~/workspace/pip-part1$ ant -p 
user@user:~/workspace/pip-part1$ ant print-hosts
user@user:~/workspace/pip-part1$ ant deploy -Dhost=partner-test.rmm.com 

“partner-test”是服务器partner-test.rmm.com 的简称。我通过类比“partner” - machine.partner.rmm.com 来做到这一点(我不知道它是如何做到的)。

现在 pom.xml 文件看起来像

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.rmm.pipproject</groupId>
    <artifactId>pip</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <profiles>
     <profile>
       <id>partner-test</id>
       <activation>
          <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
          <server>partner-test.rmm.com</server>
        </properties>
      </profile>
    </profiles>
    <modules>
        <module>pip-part1</module>
        <module>pip-part2</module>
        <module>pip-part3</module>
        <module>pip-part4</module>
    </modules>
</project>

开始连接真是太好了,但我的目标还没有达到。我无法部署项目。

user@user:~/workspace/pip-part1$ ant deploy -Dhost=partner-test.rmm.com
Buildfile: /home/user/workspace/pip-part1/build.xml

check-dist-directory:
is-dist-exists:    
deploy:
     [echo] start
      [scp] Connecting to partner-test.rmm.com:22
      [scp] Connecting to partner-test.rmm.com port 22
      [scp] Connection established
      ....
      [scp] Authentications that can continue: publickey,keyboard-interactive,password
      [scp] Next authentication method: publickey
      [scp] Authentications that can continue: password
      [scp] Next authentication method: password
      [scp] Disconnecting from partner-test.rmm.com port 22

BUILD FAILED

很明显它无法获得身份验证,尽管我已经在 build.xml 文件中编写了通过公钥登录的方法。

<target name="deploy" depends="check-dist-directory,is-dist-exists" description="deploy web application on production server">
    <echo>start</echo>
    <scp file="target/pip.war" todir="pip@${host}:/var/lib/tomcat6/pip" keyfile="${user.home}/.ssh/id_rsa"  verbose="true"/>
    <echo>end</echo>
</target>

最佳答案

如果我正确理解你的问题,你需要定义一个 Maven 配置文件“partner-test”。您可以在不同位置定义配置文件:

  • 项目 (pom.xml)
  • 用户 (%USER_HOME%/.m2/settings.xml)
  • 全局 (%M2_HOME%/conf/settings.xml)
  • 配置文件描述符 - 位于项目 basedir (profiles.xml) 中的描述符

参见Introduction to Build Profiles

您的项目 Pom 可能类似于:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <profiles>
    <profile>
      <id>partner-test</id>
      <activeByDefault>true</activeByDefault>
      <distributionManagement>
        <repository>
           <uniqueVersion>false</uniqueVersion>
           <id>test-parner</id>
           <name>Corporate Repository</name>
           <url>scp://repo/test-partner....</url>
           <layout>default</layout>
        </repository>
        <snapshotRepository>
          <uniqueVersion>true</uniqueVersion>
          <id>testSnap</id>
          <name>Propellors Snapshots</name>
          <url>sftp://propellers.net/maven</url>
          <layout>legacy</layout>
        </snapshotRepository>

      </distributionManagement>
    </profile>
  </profiles>
</project>

更详细的信息可以在POM Reference上找到页。

关于java - 添加有关新主机的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27291161/

相关文章:

java - 如何在 Android 中发送 HTTP 基本身份验证 header ?

java - char类型可以归类为整数吗?

java - WebSecurityConfigurerAdapter 中 httpBasic 和 jdbcAuthentication 的用户验证问题

maven - 如何使用 maven 从 Ivy 存储库下载 Artifact

scala - maven Scala 插件默认使用什么 Scala 版本?

java - 创建名为 : Injection of autowired dependencies failed, 的 bean 时出错,无法解析占位符

Java,LDAP : Make it not ignore blank passwords?

java - 如何在 Maven 中创建 zip 目标而不是 jar?

java - 如何解决 java.lang.NoClassDefFoundError : org/apache/logging/log4j/Logger while the class is actually accessible

java - 如何解决 Eclipse 中自定义库的 NoSuchMethodError