Please help me I am new to Maven. I am trying to generate a target folder in different directory from the Maven project folder. According to my requirements, the generated war file should be placed in another folder like C:\naresh folder when I build my maven project.
Here my code:
<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/xsd/maven-4.0.0.xsd">
<packaging>war</packaging>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>C:\Software\${project.basedir}/target</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
@khmarbaise is correct, with maven you are better off following conventions where possible – otherwise you should use a different build tool or you end up fighting it the whole way. That said, you can do the following to achieve your goal:
This uses the
user.homesystem property as the root directory, and creates the output directory in a folder named after the<artifactId/>(‘project’). All of the Java system properties are available in the pom. If you need this to be created elsewhere, you can just make it relative to the directory above.Using maven-war-plugin instead:
Since your question indicates that you really just need the artifact (war file) output to a different directory, I suggest that you modify the configuration for the output directory in the maven-war-plugin. For example: