Reputation: 2209
I have existing two maven projects, I want to combine them after build into one project. I have not created these projects module wise, the two projects are separate maven projects. Below is the POM xml code part from existing projects.
Project One pom.xml
<groupId>com.olex</groupId>
<artifactId>olex-reg</artifactId>
<version>1.0</version>
<packaging>war</packaging>
Project Two pom.xml
<groupId>com.olex</groupId>
<artifactId>olex-qba</artifactId>
<version>1.0</version>
<packaging>war</packaging>
Combine Project pom.xml
<groupId>com.olex</groupId>
<artifactId>olex-war</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
I want to combine these projects into one like olex-war
, A complete project.
After build I want all the code to be copied to this olex-war
project.
Please suggest / provide hint if anyone aware of such scenario.
Thanks in advance.
Upvotes: 2
Views: 2066
Reputation: 9941
You should combine your projects manually. Many elements (like config files) need manual merging anyway and you want to avoid to accidentally loose something from one project because the other overwrites it quietly.
This would be a horrible mind-dulling task if there were not Version Control Systems to help you with the merging.
First set up a version control system (VCS). It will help in many other situations as well. I recommend git, but if you have another already up and running that should do it just fine, I won't use any fancy specials here.
Then create an empty folder for the new project and copy all the data from the first project into it. Do all replacements as you see fit (web.xml, pom.xml, other config files) and commit it to the VCS.
This will write this version of all files into the VCS and you cannot loose them again, so if you happen to make a mistake, no worries, just revert all changes back to this point.
Then copy the content of the second project over it overwriting everything thats duplicate.
Now you can use the "show differences" feature of your VCS to see what you'll need to merge. Most likely you can do so in a graphic tool so that makes it easy.
Most of them will be "unknown" that is, the new file does not exist in the VCS, yet. Most likely you can just add them to the VCS and be done with them. More interesting are the ones that are "modified". That means the file already existed and the other project contained them as well. You will have to merge them into a combined version that is from now on valid for your new project.
When you are done you should have all the files (including pom.xml) necessary for the new project ready. Commit them to the VCS to not loose this state in the future.
Upvotes: 0
Reputation: 2039
You could start with a pom like this, that extract all the content of your old war files into content directory. Then you could package everything in that directory (except for web.xml and other metadata) in your new war.
<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.olex</groupId>
<artifactId>olex-war</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>olex-war Maven Webapp</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>olex-war</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>unpack</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.olex</groupId>
<artifactId>olex-qba</artifactId>
<version>${project.version}</version>
<packaging>war</packaging>
</artifactItem>
<artifactItem>
<groupId>com.olex</groupId>
<artifactId>olex-reg</artifactId>
<version>${project.version}</version>
<packaging>war</packaging>
</artifactItem>
</artifactItems>
<excludes>WEB-INF/web.xml</excludes>
<includes>**/*.class, **/*.jar, **/*.properties</includes>
<outputDirectory>${project.build.directory}/content</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Upvotes: 2