FANDOM


mavn force update from remote Edit

#-U means force update of dependencies
mvn clean install -U


maven with JDK Edit

  • maven 3.2 requires jdk 1.6 or above, maven 3.0/3.1 require jdk 1.5 or above

oschina maven repo Edit

configure mavenEdit

create a simple java projectEdit

  • check your ~/m2/settings.xml
  • create project with archetype plugin
mvn archetype:create -DgroupId=com.lokvin -DartifactId=baseman -DarchetypeArtifactId=maven-archetype-quickstart
mvn archetype:generate -DgroupId=me.lokvin.example -DartifactId=SpringExample -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
  • create a new github repository
touch README.md
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/xxxx/baseman.git
git push -u origin master
  • make it to eclipse project
>cd baseman
>mvn eclipse:eclipse

mvn archetype Edit

mvn download source code Edit

mvn dependency:sources

mvn dependency tree Edit

mvn dependency:tree

settings.xml Edit

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <localRepository/>
      <interactiveMode/>
      <usePluginRegistry/>
      <offline/>
      <pluginGroups/>
      <servers/>
      <mirrors/>
      <proxies/>
      <profiles/>
      <activeProfiles/>
</settings>
Element Name Description
localRepository Maven 用来存储 plugins 和 dependencies 的本地目录。 默认为 ~/.m2/repository. 可以通过这个属性来指定别的目录
interactiveMode Default is true. Maven interact with user for input
offline Default is false. When set true, maven operate in offline mode
servers Maven can interact with a variety of servers, such as: SVN, build server, remote repository server. This element specify security credentials. such as username, passwd which connect to these server
mirrors specify alternative locations for your respositories
proxies http proxy information connect to internet
profiles profiles allow to group certain configuration elements, such as: repositories and pluginRepositories
activeProfile activeProfile allow you specify default profile to be active for maven use

maven dependency management Edit

EnterpriseMavenRepository

Enterprise Maven repository architecture

MavenRepositoryManagement

Maven Dependency Management

opensource repository managers Edit

maven create spring example project Edit

  • create empty project
mvn archetype:generate -DgroupId=me.lokvin.example -DartifactId=SpringExample -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

maven dependency scope Edit

  • compile

This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

  • provided

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

  • runtime

This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

  • test

This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.

  • system

This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

  • import (only available in Maven 2.0.9 or later)

This scope is only used on a dependency of type pom in the <dependencyManagement> section. It indicates that the specified POM should be replaced with the dependencies in that POM's <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.