Skip to content

Instantly share code, notes, and snippets.

@oldratlee
Last active December 17, 2015 02:59
Show Gist options
  • Save oldratlee/5540208 to your computer and use it in GitHub Desktop.
Save oldratlee/5540208 to your computer and use it in GitHub Desktop.
download file and add it to war file via maven

How to Activate

Activate

mvn install -P Profile-Download-Extra-Resources

Under below pom, Profile-Download-Extra-Resources is activated by default.

Deactivate

mvn install -P '!Profile-Download-Extra-Resources'

Details on profile activation

Details on profile activation

Sample POM file

<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.oldratlee.demo</groupId>
	<artifactId>war-resources-demo</artifactId>
	<packaging>war</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>${artifactId}</name>

	<dependencies>
	</dependencies>

	<profiles>
		<profile>
			<id>Profile-Download-Extra-Resources</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>wagon-maven-plugin</artifactId>
						<executions>
							<execution>
								<id>download-file</id>
								<phase>prepare-package</phase>
								<goals>
									<goal>download-single</goal>
								</goals>
								<configuration>
									<url>http://foo.com/</url>
									<fromFile><![CDATA[foo.tgz?AccessKeyId=xx&Expires=1998305368]]></fromFile>
									<toFile>${project.build.directory}/extra-resources/foo.tgz</toFile>
								</configuration>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-war-plugin</artifactId>
						<configuration>
							<webResources>
								<resource>
									<!-- this is relative to the pom.xml directory -->
									<directory>
										${project.build.directory}/extra-resources
									</directory>
								</resource>
							</webResources>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment