1

I have put up a maven project on git repository which is using maven-war-plugin to create war directly in tomcat directory. But on different systems, tomcat directory path can be different.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <outputDirectory><file-path></outputDirectory>
            </configuration>
        </plugin>

I want this outputDirectory parameter to be configurable without needing to change pom.xml on local systems.

Tome
  • 3,234
  • 3
  • 33
  • 36
Shashwat Kumar
  • 5,159
  • 2
  • 30
  • 66
  • You can try using properties (users will have their own values in their user `settings.xml`) or use environment variables – Tome Feb 14 '17 at 08:40
  • 1
    Check out the answer by @EricGreg in this SO post:https://stackoverflow.com/questions/10463077/how-to-refer-environment-variable-in-pom-xml – ali4j Oct 15 '18 at 05:02

2 Answers2

0

I faced the exact same issue and I resolved it by putting the below plugin in my POM file.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>                            
            </resource>
        </resources>
    </configuration>
</plugin>  


<properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Suresh
  • 1,491
  • 2
  • 22
  • 27
  • This is good solution but it mandates to keep configurable resource inside project directory. The environment variable seems apt solution. – Shashwat Kumar Oct 15 '18 at 05:10
0

As ali4j mentioned in comment, using env variable is appropriate solution for this scenario. Use a custom env variable in POM and ask the users to set the env in their system. How to refer environment variable in POM.xml?

Shashwat Kumar
  • 5,159
  • 2
  • 30
  • 66