2011-07-01 6 views
26

tomcat-maven-pluginを使って私の戦争をサーバに展開します。Maven - <server/> in settings.xml

<configuration> 
... 
    <url>http://localhost/manager</url> 
    <username>admin</username> 
    <password>admin</password> 
... 
</configuration> 

をしかし、私は明らかに私は自分のコンピュータ上で動作しますが、その後、ステージングがありますので、別の場所にこの設定を保存しておきたいと:私は何をしているのは、私のpom.xmlでこのようにそれを構成していますサーバーの設定が異なるライブサーバーも含まれます。

それでは.m2/settings.xmlを使ってみましょう:

<servers> 
    <server> 
     <id>local_tomcat</id> 
     <username>admin</username> 
     <password>admin</password> 
    </server> 
</servers> 

は今のpom.xmlを変更:

<configuration> 
    <server>local_tomcat</server> 
</configuration> 

しかし、ここでサーバーのURLを入れて?そのための場所はserverタグのsettings.xmlにありません!これはどう?

<profiles> 
    <profile> 
    <id>tomcat-config</id> 
     <properties> 
    <tomcat.url>http://localhost/manager</tomcat.url> 
     </properties> 
    </profile> 
</profiles> 

<activeProfiles> 
    <activeProfile>tomcat-config</activeProfile> 
</activeProfiles> 

.. $ {tomcat.url}プロパティを使用します。

しかし、なぜ、サーバータグをsettings.xmlに使用するのが問題なのですか?なぜユーザー名とパスワードのプロパティも使用しないのですか?または、URLの場所も設定URLにありますので、プロパティを使用する必要はありませんか?

答えて

29

まず、profilesはMavenの最も強力な機能の1つです。

<profiles> 
    <profile> 
     <id>tomcat-localhost</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <properties> 
      <tomcat-server>localhost</tomcat-server> 
      <tomcat-url>http://localhost:8080/manager</tomcat-url> 
     </properties> 
    </profile> 
</profiles> 

は、その後、あなたの ~/.m2/settings.xmlファイルに次のように serversエントリを追加します:

まず、このようになりますあなたのpom.xmlでプロファイルを作る

<servers> 
     <server> 
      <id>localhost</id> 
      <username>admin</username> 
      <password>password</password> 
     </server> 
    </servers> 

のconfigureこのようなあなたのbuildプラグインを:

<plugin> 
    <!-- enable deploying to tomcat --> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>tomcat-maven-plugin</artifactId> 
    <version>1.1</version> 
    <configuration> 
     <server>${tomcat-server}</server> 
     <url>${tomcat-url}</url> 
    </configuration> 
</plugin> 

これにより、デフォルトでtomcat-localhostのプロファイルが有効になり、簡易mvn clean package tomcat:deployで展開できるようになります。

他のターゲットに展開するには、適切な資格情報を使用してsettings.xmlに新しい<server/>エントリを設定します。新しいprofileを追加しますが、<activation/>スタンザを省略し、適切な詳細を指すように構成してください。

次に使用するmvn clean package tomcat:deploy -P [profile id][profile id]は新しいプロファイルです。

資格がsettings.xmlに設定されている理由は、ほとんどの場合、ユーザー名とパスワードを秘密にする必要があり、人々が適応する必要があるサーバー資格情報を設定する標準的な方法から逸脱する理由がないからです。

+0

これをもう少しクリアにしていただきありがとうございます:) –

関連する問題