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>
A Build profile is a set of configuration values, which can be used to set or override default values of Maven build. Using a build profile, you can customize build for different environments such as Production v/s Development environments. Profiles are specified in pom.
mvn/maven. config is located in the ${maven. projectBasedir}/. mvn/ directory; also works if in the root of a multi module build.
Maven has a settings file located in the Maven installation and/or user home directory that configure environmental specifics such as: HTTP proxy server. repository manager location. server authentication and passwords.
The WAR Plugin is responsible for collecting all artifact dependencies, classes and resources of the web application and packaging them into a web application archive.
@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:
<build>
<outputDirectory>${user.home}/${project.artifactId}/target</outputDirectory>
...
</build>
This uses the user.home
system 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:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<outputDirectory>${user.home}/${project.artifactId}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
The first thing you have to learn about Maven is: Maven has it's conventions one of those conventions is having a target folder which is located under the current project and not somewhere else. And furthermore and absolute no-go is putting some absolute folder definitions into your pom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With