Maven nicely automates building WAR files, but it places your compiled classes in WEB-INF/classes instead of making a new jar in /WEB-INF/lib.
If you want your code to be compiled as a .jar as well as a .war, you can do this by specifying the jar goal in the command line:
[shell>mvn clean jar install
Note this will make myproject.jar in target/, not in target/myproject/WEB-INF/lib, so you will need to use the Ant plugin to move this stuff around.
But this is not always an option: for deep, modular builds using the reactor, you may want to build your whole thing using one “mvn install”. To do this, do the following:
- Specify “war” packaging at the top of your pom.xml.
- Then add the following to your build section.
<?xml version="1.0" encoding="UTF-8"?>
And that’s it. Do a “maven install” and you get both a jar as well as a war.
Apache Maven is a project management software, managing building, reporting and documentation of a Java development project. In order to install and configure Apache Maven on CentOS, follow these steps.
First of all, you need to install Java 1.7 JDK. Make sure to install Java JDK, not JRE.
Then go ahead and download the latest Maven binary from its official site. For example, for version 3.0.4:
$ wget http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz
$ sudo tar xzf apache-maven-3.0.5-bin.tar.gz -C /usr/local
$ cd /usr/local
$ sudo ln -s apache-maven-3.0.5 maven
Next, set up Maven path system-wide:
$ sudo vi /etc/profile.d/maven.sh
Finally, log out and log in again to activate the above environment variables.
To verify successful installation of maven, check the version of maven:
$ mvn -version
Optionally, if you are using Maven behind a proxy, you must do the following.
$ vi ~/.m2/settings.xml