1, first to install MAVEN to the operating system
Maven download page: http://maven.apache.org/download.html
Maven is like Tomcat, download it and unzip it directly in the specified directory to install successfully, but MAVEN is more than tomcat an environment variable configuration
Current version 3.0.3. Unzip the downloaded file,
First create a system variable M2home, the value of the variable points to Maven's extract directory:
Set the bin directory in the Windows PATH environment variable. Just add the%m2home%\bin to the path system variable:
To test whether the installation was successful: on the command line, enter
Mvn-version
If the installation succeeds, the output looks like this:
2. Install Eclipse's Maven plugin
Install Eclipse's Maven plugin m2eclipse.
M2eclipse Plugin URL: http://m2eclipse.sonatype.org/installing-m2eclipse.html
Update website via eclipse Online: m2eclipse Core Update site:
Http://m2eclipse.sonatype.org/sites/m2e
Follow the same steps as installing other plugins
(
The following error was encountered when installing the MAVEN plugin on Eclipse today:
Cannot complete the install because one or more required items could not be found.
Software being Installed:maven integration for Eclipse (Required) 0.12.1.20110112-1712 ( Org.maven.ide.eclipse.feature.feature.group 0.12.1.20110112-1712)
Missing Requirement:maven Integration for Eclipse (Editors) 0.12.1.20110112-1712 (org.maven.ide.eclipse.editor 0.12.1.20110112-1712) requires ' bundle Org.eclipse.zest.core 0.0.0 ' But it could wasn't be found
Cannot satisfy dependency:
From:maven Integration for Eclipse (Required) 0.12.1.20110112-1712 (org.maven.ide.eclipse.feature.feature.group 0.12.1.20110112-1712)
To:org.maven.ide.eclipse.editor [0.12.1.20110112-1712]
The feeling is less MAVEN relies on the Eclipse plug-in, the online search, the solution is as follows:
Launch Eclipse, click window-->preferences-->install/update-->available Software Sites, click Add
Add the following information:
GEF http://download.eclipse.org/tools/gef/updates/releases/
Then reinstall the MAVEN plugin
)
Note that after the installation is integrated with the locally extracted maven, there are two changes that need to be made:
First place: window-preferences, pop-up window:
Second outside: Truly integrated actions:
3, start eclipse will prompt warning: Can not find JDK what, the solution:
Add the following two lines to the Eclipse.ini (Eclipse.ini in the Eclipse installation directory) file (the location where the VM points to javaw.exe, or directly to the bin):
+v+
C:\Program Files\java\jdk1.6.0_06\bin\javaw.exe
But here are a few things to note:
Note: To write in two lines, write on a line that does not take effect
Note: These two lines will not be valid until-vmargs.
Note: The last line can also be written as C:/Program files/java/jdk1.6.0_16/bin/
4. Hint Unable to locate the Javac Compiler in:
Workaround:
Installed JREs, Java-Preferences, window, click on the "Add" button, select the default "Standard VM", click "Next >",
Click on "JRE Home" to the right of "Directory" Select Folder C:\Program Files\java\jdk1.6.0_06\jre, all the Way "OK", back to "Installed JREs" interface,
Tick the "jdk1.6.0_06" that you just added. Then select "Execution Environments" in the directory tree, click "j2se-1.6" to the left of the interface,
Then click "Jdk1.6.0_06" on the right. Restart Eclipse, everything OK.
The problem is that the system has two JRE installed and should use the JRE in the JDK.
or edit the existing JRE, then click the Add Extends jars button, add the Jdk\lib\tools.jar file, the same can be resolved.
However, it is important to note that you have created a MAVEN project reference or the original JRE, to modify it, after executing the above steps, right-click the project name->build path->configure Build path-> Under the Library tab, select the referenced JRE, remove it, and click the Add Library button on the right, select the JRE System Library, follow the default action, Next-finish, and the original project is changed.
Original address:
http://blog.csdn.net/shanliangliuxing/article/details/6982767
The MAVEN plugin installed on eclipse encountered a reference address for the following error solution:
http://v-vampires.iteye.com/blog/988290
What is Maven
Maven, the famous, before today, I have been in a state of "only smell its name is not the person". Because Maven is so famous, it is the top project of the Apache Foundation, and in general, it is a boutique that is what Apache is all about. The reason to say "no one" is that Maven was not used in previous jobs, so it is not familiar to Maven.
It happened that I had recently changed my job and the project in my new job was built using MAVEN, which made it necessary for me to use MAVEN. Therefore, this article on the zero start of Maven to learn, in my learning process, inevitably encountered a lot of problems, in thinking, solve these problems at the same time, the output of some words, I believe it will be helpful to friends of the netizens.
OK, so let's get started.
What is Maven's role?
This is the first question I have encountered, even after reading some MAVEN data, I still have questions, what exactly is maven used for? After continuing to study and I wrote the example, I have a certain sentiment, the following try to answer this question. First, if you use the traditional way of building a project, there may be confusion:
- Development, in order to ensure that the compilation through, we will go everywhere to find the jar package, when the compilation passed, run, but found "classnotfoundexception", is not the jar package? Look for it again.
- The directory structure of each Java project does not have a uniform standard, and the configuration files are everywhere, where unit test code should be placed there is no authoritative specification
So we're going to use MAVEN (using ant, but it's a hassle to write an ant XML script)----A project management tool . Maven has done two things mainly:
- Unified Development Specification and tools
- Unified Management Jar Package
Let's compare the first to create a common Java project, like this:
We are very familiar with this, SRC under the package to write code, then the configuration file where? Where is the unit test code placed? Without a single standard, more often developers are free to play, everyone has their own style, which is not very suitable for team collaboration. Next, look at the directory structure after using MAVEN to build a common Java project:
See common Java projects built with MAVEN, with dedicated directory planning for source code, unit test code, resources, and even files that need to be followed.
At the end there is a pom.xml, which is MAVEN's core configuration file, which is called the project object Model , which is used to describe the entire MAVEN project, so also known as the Maven profile.
Of course it won't be that simple, so go ahead and go into Maven's world.
Pom.xml
Open the Pom.xml, the most basic is this:
<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" > <modelVersion>4.0.0</modelVersion> <groupId>com.xrq.withmaven</groupId> <artifactId>withmaven</artifactId> <version>0.0.1-SNAPSHOT</version> <build /></project>
Because this configuration file is the core of MAVEN, it is necessary to read the Pom.xml in more detail, to look at the above several:
1, Modelversion
Specifies the version number of the current MAVEN model, which can only be 4.0.0 for Maven2 and Maven3
2, GroupId
As the name implies, this should be the company name or organization name. Generally speaking, GroupID is made up of three parts, each with "." Separation, the first part is the purpose of the project, for example, commercial is "com", for the non-profit organization is "org", the second part is the company name, such as "Tengxun", "Baidu", "Alibaba"; the third part is your project name.
3, Artifactid
Can be thought of as a project name that Maven builds, such as having a subproject in your project, you can use the name of the project name-subproject name
4. Version
The version number, snapshot, means that the project is still in development and is not a stable version. It is important in Maven that thegroupId, Artifactid, and version three elements generate the basic coordinates of a MAVEN project , which is very important, and I have felt this many times when using and studying MAVEN.
In addition to these elements above, there are some elements that also list the following:
1, packing
The type of project package that enables Jar, war, rar, ear, POM, default is jar
2, dependencies and dependency
The former contains the latter. As I said earlier, one of Maven's important roles is to manage the jar package in a unified way, and for a project to build or run, the project inevitably relies on many other jar packages, which are called dependency in maven.
Speaking of which, there is a concept of a local repository and a remote repository . Official download of the local warehouse configuration in the "%maven_home%\conf\settings.xml", Look for "localrepository" on it; myeclipse the address of the default local warehouse in the "{user.home}/.m2/ Repository "path, also look for" localrepository "can find myeclipse default local repository.
Local warehouses and remote repositories This is thefirst time that the MAVEN project gets the jar package from the local repository, and when the specified jar package cannot be obtained, the local repository downloads the jar package from the remote warehouse (central warehouse) and puts it in the local repository for future use .
For example, if I use MyBatis in my project, I can configure this:
<dependencies> <dependency> <groupId>org.mybatis</groupId> <artifactid >mybatis</artifactId> <version>3.2.5</version> </dependency></ Dependencies>
Previously said GroupID, Artifactid, version uniquely identify a MAVEN project, with these three elements, we can go to the remote repository to download Mybatis3.2.5.jar to the local repository. Recall our previous practice, if you want to mybatis the jar package, found that there is no, then go to the Internet to download one, need another jar package, and then go online to download one, but with Maven, it is more convenient, only need to configure the jar package corresponding to the dependency dependency, MAVEN will automatically help us to download the jar package to the local repository in the remote repository.
3. Properties
Properties are used to define some configuration properties, such as project.build.sourceEncoding (project build source code), can be set to UTF-8, prevent Chinese garbled, can also define the relevant build version number, easy to upgrade later.
4. Build
Build represents a build-related configuration, such as a finalname under build, that represents the name after the final build.
MAVEN Engineering Directory Structure
Back to the picture above:
Then explain the MAVEN directory structure:
- The main directory is the primary code for the project, where the test-related code is stored
- The code after compiling the output will be placed in the target directory
- Src/main/java store Java code, src/main/resources under the configuration file
- There is no Webapp,web project there will be WebApp directory, WebApp to store the Web app related code
- Pom.xml is a configuration file for the MAVEN project
MAVEN Environment Configuration
Common development tools idea, myeclipse inside have already integrated maven, but preferably from the website next configuration to their own computer, development tools may have a little bug.
First go to MAVEN official website, download Maven's package, address for http://maven.apache.org/download.cgi, find the following section, click on it to download:
Download the decompression, then configure the environment variables, similar to the JDK environment variable configuration:
This configuration is ready, verify that, windows+r Open the Command window, enter "MVN--version", if there is the following content this means MAVEN configuration OK:
Getting Started with Maven FAQ
1. I downloaded a project from SVN that I built with MAVEN, but what if I download it without a jar package?
The MAVEN project downloaded from the repository is not a jar package, so you can do this at this time:
(1) Delete Maven project, but do not delete the MAVEN project inside the local project, delete only maven project in MyEclipse
(2) Right-click import->maven4myeclipse->existing maven Projects to import your Maven project, at this time MyEclipse in the construction project, If you do not have a jar package in the Dependcy in your local repository, you will go to the remote repository to download the jar package to the local repository. After your project has been imported, the library should look like this:
2. To re-download the jar package that the MAVEN project relies on, and import the jar package to trigger the MAVEN project build workspace, how can I trigger the MAVEN project build workspace?
Find a pom.xml, casually modify, add a space, minus a space or something, ctrl+s save, it will trigger the MAVEN project build workspace
3. What is the directory structure of the local warehouse?
GroupId, Artifactid, and version determine a unique maven, let's say I have a mybatis dependcy:
<dependency> <groupId>org.mybatis</groupId> <artifactid>mybatis</artifactid > <version>3.2.5</version></dependency>
Then MyBatis jar package should be in the%maven warehouse address%\org\mybatis\mybatis\3.2.5\ This path, see, First GroupID, then MyBatis, the last version, each name is a folder name
4, some jar package in the Dependcy inside has the configuration, import the MAVEN project, after downloading the project to rely on the jar package, found that the local warehouse is not, how to do?
Maybe it was something wrong when I downloaded the jar package, start by deleting all of the following files/folders from the Artifactid directory, and then trigger the MAVEN project build workspace.
5, the local warehouse identified already have jar package, the project inside but error, said can not find jar package, how to do?
There should be a lot of solutions, and one way to solve it now is to,myeclipse->window->preferences-> search Maven->user settings,update Settings and Reindex just a little bit better. Alternatively, you can try removing the jar package from your local maven repository and then re-build workspace, possibly.
Introduction to Maven and integration of Eclisp