質問
全体的な目標
静的コンテンツを含むフォルダーにバージョン番号が追加されたJavaWebApp(warファイル)を作成して、キャッシュ可能にします。名前の変更は、ビルド中に自動的に行われる必要があります。
詳細
WebAppは、すべての静的コンテンツがフォルダー内にグループ化されるように既に構造化されています。
- / lib->すべてのJavaScriptライブラリ(例:/lib/angular-1.0.3(src / main / webappのソース))
- /app->現在の自分のコード/app/ myApp(src / main / webappのソース)
- / api->すべての動的サーブレット(ソースはsrc / main / java)
- index.jsp->WebAppをブートストラップするホストページ
/ apiおよびindex.jspで始まるものはすべて動的であり、キャッシュできません。
/ libで始まるものはすべて静的でバージョン管理されているため、「access+12month」のexpiresヘッダーを設定できます。コンテンツの変更には、新しいバージョン番号が必要です。ライブラリはバージョン番号がハードコーディングされているため、ほとんど変更されないため、これは簡単です。
私自身のアプリ(AngularJSで構築されたもの)も静的であるため、expiresヘッダーも「アクセス+12か月」に設定したいと思います。そのためには、Mavenの現在のバージョン番号をフォルダー名の最後に追加する必要があります。これにより、/ app/myAppをソースディレクトリからターゲットディレクトリ/finalwarファイルの/app/myApp-1.2.3に変更します。
POMファイル
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>jslint</goal>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeResources>true</excludeResources>
<removeIncluded>true</removeIncluded>
<suffix>.min</suffix>
<excludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.properties</exclude>
<exclude>**/lib/**/*.js</exclude>
<exclude>**/lib/**/*.css</exclude>
</excludes>
<aggregations>
<aggregation>
<insertNewLine>true</insertNewLine>
<output>${project.build.directory}/${project.build.finalName}/app/myApp/js/all.min.js</output>
<includes>
<include>${project.basedir}/src/main/webapp/app/myApp/js/header.txt</include>
<include>**/*.min.js</include>
</includes>
</aggregation>
</aggregations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingFile>false</ignoreMissingFile>
<file>${project.build.directory}/myApp/index.jsp</file>
<replacements>
<replacement>
<token>PROJECT_VERSION</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
すべてのリソースをtarget-directoryにコピーし、yuicompressorを実行し、リンクを更新して、app/myAppの名前をapp/myApp-xyzに変更する方法を探しています。
リンクの圧縮と更新はすでに行われていますが、ビルド時に自分のアプリの名前を変更する方法が見つかりません。
ありがとう
解決
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>jslint</goal>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeResources>true</excludeResources>
<removeIncluded>true</removeIncluded>
<suffix>.min</suffix>
<failOnWarning>true</failOnWarning>
<excludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.properties</exclude>
<exclude>**/lib/**/*.js</exclude>
<exclude>**/lib/**/*.css</exclude>
</excludes>
<sourceDirectory>${project.basedir}/src/main/webapp/app/myApp</sourceDirectory>
<outputDirectory>${project.build.directory}/${project.build.finalName}/app/myApp-${project.version}</outputDirectory>
<aggregations>
<aggregation>
<insertNewLine>true</insertNewLine>
<output>${project.build.directory}/${project.build.finalName}/app/myApp-${project.version}/js/all.min.js</output>
<includes>
<include>${project.basedir}/src/main/webapp/app/myApp/js/header.txt</include>
<include>**/*.min.js</include>
</includes>
</aggregation>
</aggregations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<useCache>true</useCache>
<!-- this exclude the directory to rename from the default copy resources procedure -->
<warSourceExcludes>app/myApp/**,.idea/**</warSourceExcludes>
<!-- this will do the renaming : i.e. we specify the source directory relative to pom.xml and the target directory relative to root -->
<webResources>
<resource>
<directory>src/main/webapp/app/myApp</directory>
<excludes>
<exclude>**/*.js</exclude>
</excludes>
<targetPath>/app/myApp-${project.version}</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingFile>false</ignoreMissingFile>
<file>${project.build.directory}/myApp/index.jsp</file>
<replacements>
<replacement>
<token>%PROJECT_VERSION%</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
</plugins>