Ervis Zyka
Ervis Zyka

Reputation: 506

How to add directories to war at runtime?

When maven install goal runs it copies some directories to the src/main/resources. I want to move this functionality at runtime when the application is deployed. The idea is to pass a system variable, which will hold the directory path. When the application is deployed it should look that variable and copy the directory. What I want to achieve is to have a single war file for different environments and properly "inject" the proper configuration for the target environment.

Upvotes: 0

Views: 66

Answers (1)

lance-java
lance-java

Reputation: 27976

You can't shouldn't change the war artifact once it's built as the groupId/artifactId/version combination is considered immutable once built and can be cached.

Here's a few of common approaches to environment specific config

  1. Build multiple versions of the war, one for each environment. In maven this is usually achieved via the maven-assembly-plugin
  2. Include config for ALL environments in the war (eg src/main/resources/dev, src/main/resources/prod, src/main/resources/uat etc) and use a system property to pick which config to use at runtime
  3. Store the environment specific config outside of the war (eg on the file system) and either use a system property to specify which directory to use or have a fixed location on each machine (sit / uat / prod) with different config for each.

Upvotes: 1

Related Questions