1

For the first part : I want to generate multiple war files when I build a maven project. The second part : I want to rename those files dynamically.

For example : the file that is generated now is called test.war . If I want to generate this file multiple times on a single build I would want the files to be name like this : test_1.war, test_2.war , test_3.war...

Do you guys have any Idea how can this be achieved ? I can also create a .bat file that would do those things but I am not quite sure how :)

Thank you

Sebastian
  • 617
  • 2
  • 10
  • 30
  • check [this](http://stackoverflow.com/questions/1882322/how-do-i-get-maven-2-to-build-2-separate-war-files) – Hohenheim Apr 04 '16 at 13:30
  • Thank you but unfortunately that does not apply to my case. I have only one project, with one web.xml and I want to use this file for all the files that are generated. Basically what I want to do is a loop of the part that is generating the war file creating more than one file. – Sebastian Apr 04 '16 at 13:53
  • I strongly suggest to build a multi module maven project, where each war is the output of a single module. that's an answer to generate multiple war files. For the renaming i think create profiles is the best solution you can refer to [this](http://stackoverflow.com/questions/6129581/in-maven-how-to-rename-the-output-war-file-based-on-the-name-of-the-profile-i) hope that will help – Hohenheim Apr 04 '16 at 13:59
  • Thank you, indeed it would be much better solution to have a multi module project, but that would mean in my situation I would have duplicated code. I was thinking maybe I could do a .bat file with a for loop in which i could have something like "mvn clean install", but here comes the renaming problem because every time when I create the file it will have the same name – Sebastian Apr 04 '16 at 14:07
  • I don't know if it exist a solution with .bat file but you can keep your post until someone else could find an appropriate solution. Good Luck – Hohenheim Apr 04 '16 at 14:41
  • 1
    The basic question here is: Why do you need multiple war files? should they contain different files? or what? – khmarbaise Apr 04 '16 at 16:14
  • Hello, the war files would have to contain the same files but with different configurations. For example for the test_1.war file I would have testClass.java with a variable var = test_1, and for test_2.war I would have testClass.java with the variable var = test_2. But this I would have to configure in another way – Sebastian Apr 05 '16 at 07:45

2 Answers2

5

Not entirely sure whether this works but possibly you could try something like this:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>test_1</id>
            <goals>
                <goal>war</goal>
            <goals>
            <configuration>
                <warName>test_1.war</warName>
            </configuration>
        </execution> 
        <execution>
            <id>test_2</id>
            <goals>
                <goal>war</goal>
            <goals>
            <configuration>
                <warName>test_2.war</warName>
            </configuration>
        </execution> 
    <executions>
  </plugin>
uniknow
  • 938
  • 6
  • 5
0

thank you for all your answers. I managed to create those files using a .bat file that looks like this :

call mvn -DfinalName=test_1 package call mvn -DfinalName=test_2 package call mvn -DfinalName=test_3 package call mvn -DfinalName=test_4 package

and in the pom.xml I added a property <finalName> :

<properties> <finalName>${project.artifactId}-${project.version}</finalName> </properties>

and in the build section I added this :

<build> <finalName>${finalName}</finalName>
... </build>

.

Sebastian
  • 617
  • 2
  • 10
  • 30