1

antスクリプトをMavenに移植していますが、web.xmlの変換に固執しています。

私のweb.xmlでは、開発中に次のセキュリティ制約がNONEに設定され、本番サーバー用に生成された戦争に対してCONFIDENTIALに設定されています。

<security-constraint>
    <web-resource-collection>
      <web-resource-name>HTTPSOnly</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
      <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>

XSLスクリプトを使用して、antから呼び出されるweb.xmlファイルを処理します。XSLがweb.xmlに適用され、変換されたweb.xmlが生成されたwarで使用されるwarファイルをmavenに生成させたい。

私はMavenXSLプラグインとMavenプロファイルの概念について知っていますが、すべてをまとめるのに苦労しており、状況に対処するための正しいMavenの方法がわかりません。

4

3 に答える 3

2

これを達成する方法はたくさんあります。おそらく最も簡単な方法は、maven-antrun-plugin http://maven.apache.org/plugins/maven-antrun-plugin/を使用して、既存のantタスクを呼び出すことです。

私が知っている他の方法は、変数/プレースホルダーとMavenフィルタリング(変数置換)を使用することです。http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-を参照してください。 distribution-files.html

于 2013-01-16T06:15:50.807 に答える
2

Mavenの方法は、フィルタリングを使用することです。

以下のxslを使用しない通常のweb.xmlフィルタリングの例:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <webResource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <includes>
                            <include>web.xml</include>
                        </includes>
                        <targetPath>WEB-INF</targetPath>
                        <filtering>true</filtering>
                    </webResource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
    <filters>
        <filter>src/main/filters/filter-${env}.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

xslを主張する場合は、のベースから作業して、Mavenxmlプラグインを使用できます。

 <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xml-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>transform</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <transformationSets>
            <transformationSet>
              <dir>src/main/xml</dir>
              <stylesheet>src/main/stylesheet.xsl</stylesheet>
            </transformationSet>
          </transformationSets>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
于 2013-01-16T09:53:16.063 に答える
1

次のプラグインを含むWebアプリのpom.xmlを使用してprodプロファイルを設定するという問題を解決しました。これは私にとってはうまくいきます。なぜなら、プロジェクトがEclipseにインポートされるとき、私は本当に何も派手なことをしたくないし、開発者のマシンからすべてを箱から出して動作させたいからです。以下には示されていませんが、NodeJSの呼び出しを追加して、ソースの生成フェーズでRequireJSを使用してjavascriptフロントエンドを構築しました。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>transform</goal>
            </goals>
            <configuration>
                <transformationSets>
                    <transformationSet>
                        <dir>src/main/webapp/WEB-INF</dir>
                        <includes>
                            <include>web.xml</include>
                        </includes>
                        <stylesheet>src/main/webapp/WEB-INF/web.xsl</stylesheet>
                    </transformationSet>
                </transformationSets>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webXml>target/generated-resources/xml/xslt/web.xml</webXml>
        <archiveClasses>true</archiveClasses>
        <warSourceExcludes>META-INF/context.xml</warSourceExcludes>
        <packagingExcludes>
            **/**/context.xml
        </packagingExcludes>
    </configuration>
</plugin>
于 2013-01-16T19:22:34.430 に答える