Reputation: 4026
I want to use Maven for building my next Java Project. So I have some questions about Maven before starting right off.
Does Maven need to be installed? Or can Maven binaries just be copied to a system (Windows) and be used in the same way.
Setup a Maven project required? From a Maven tutorial i've seen that the first step in Maven is to setup a Maven project like this:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Why is that? Is writing a POM file not enough when I only want to compile some Java files and include some jars?
Upvotes: 0
Views: 95
Reputation: 40036
Question 1 (Installation):
Well it mostly is simply copy, add to path, and run.
However in real world there is a bit more than that. For example,
- in a company, you may want to have a company central repository proxy. You will need to do extra set up in either HOME/.m2/settings.xml
or MVN_DIR/conf/settings.xml
(Wish I remember the path right :P )
You may want to put local repository in a different directory in some case, you will also need to change settings.xml
.
In order to have building of big project works, you may need to adjust M2_OPTS
environment variable.
etc...
All these things are extra manual installation work you may need (Not difficult though)
Question 2 (Archetype):
You are actually right. You can simply write your own pom.xml
and forget about archetype (That's what I was doing in the past too :) ). You can think Archetype as some template-project-generation feature, so that you may generate some pre-defined project types, and the essential project directory structure, required dependencies and settings in POM are all done for you. Of course you may even provide your own archetype, so new projects in your company can make use of them to conform with guideline or standard you want.
Upvotes: 2
Reputation: 1552
Answer to 1st question:
Maven is available in distributed binary format.You just have to download it and extract it in your local machine. And then, you have to create one user variable named M2_HOME(sometime M2_OPTS is also required) and add it to PATH variable. That's all you need to set up basic needs.
If your system is inside some proxy network then you have to perform one additional settings. That is to copy secuirity xml, which is available inside the downloaded files, and modify the elements values inside it according to your network.
Answer to 1st question:
For the 1st time you need to use the command you specified. Once you get the file-structure, you may reuse it based on your need. But remember to follow predefined file-structure else you would be surely in a trouble.
However,it's always advisable to create the projects using maven command as it would do many things for you which you might have to do manually if you opt for manual maven project creation.
Upvotes: 1
Reputation: 137084
- Does Maven need to be installed? Or can Maven binaries just be copied to a system (windows) and be used in the same way.
Maven comes bundled as a zip
archive that you just need to unzip. You then need to add the bin
directory to the PATH environment variable and you are good to go.
Setup a Maven project required? From a Maven tutorial i've seen that the first step in Maven is to setup a Maven project like this:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
There are multiple ways to create a Maven project. However, it is important to remember that a Maven project only comes down to having a single pom.xml
file. This file will be located at the root of your project. So you are right when you say that "writing a POM file is enough".
Now, since Maven is a tool that is built under the convention-over-configuration principle, several utilities have been created to help adhere with the basic conventions of Maven. One of those utilities is the maven-archetype-plugin
, which is invoked by the call to mvn archetype:generate
. This utility will create a basic pom.xml
file along with the standard directory layout.
If you are using an IDE, you could also create a Maven project by using the corresponding Maven plugin of this IDE (for example for Eclipse, this is the M2Eclipse plugin).
Upvotes: 2