maven下载依赖jar包的源码和javadoc:
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
maven多模块示例:
假设在名字为simple-parent的文件夹下面有一个pom.xml (也就是所谓的父模块pom.xml)、一个名字为 firstChild 的文件夹(里面是一个maven子模块)、一个名字为secondChild的文件夹(里面也是一个maven子模块)
其中父模块pom.xml 内容为:
注意:模块的加载顺序和该模块在父模块的pom.xml中配置的顺序有关,例如下面的firstChild就会先于secondChild模块
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tch</groupId>
<artifactId>maven-parent</artifactId>
<!-- 父模块的packaging要配置为pom,表明这是个单纯的pom文件 -->
<packaging>pom</packaging>
<version>1.0</version>
<name>Chapter 6 Simple Parent Project</name>
<modules>
<!-- 这里配置子模块的artifactId列表 -->
<module>firstChild</module>
<module>secondChild</module>
</modules>
</project>
firstChild 的pom.xml :
<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>
<!-- 这里配置父模块的坐标 -->
<parent>
<groupId>com.tch</groupId>
<artifactId>maven-parent</artifactId>
<version>1.0</version>
</parent>
<!-- 这里可以省去groupId的配置,因为该配置与父模块的groupId一样,所以可省略 -->
<artifactId>firstChild</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
secondChild 模块的pom.xml :
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 这里配置父模块的坐标 -->
<parent>
<groupId>com.tch</groupId>
<artifactId>maven-parent</artifactId>
<version>1.0</version>
</parent>
<!-- 这里可以省去groupId的配置,因为该配置与父模块的groupId一样,所以可省略 -->
<artifactId>secondChild</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>webmaven</finalName>
<plugins>
<!-- 配置jetty -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
在父pom.xml中配置 dependency 和 配置 dependencyManagement 的区别:
在父pom.xml中配置dependency的话,子模块就会继承该依赖,假如父pom.xml中配置了下面的依赖:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
然后在子模块运行下面命令查看子模块的依赖:
就会发现子模块的依赖包含了上面再父pom.xml中配置的依赖。类似于java里面继承的效果。
如果在父pom.xml中配置dependencyManagement的话,假如dependencyManagement里面配置了上面同样的依赖:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
然后在子模块运行
mvn dependency:resolve
查看子模块的依赖的话,就会发现子模块并没有继承父模块dependencyManagement里面配置的依赖。
要想使用父模块dependencyManagement里面配置的依赖,需要在子模块配置(注意没有version):
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
,然后在子模块运行
命令查看子模块的依赖,就会发现子模块的依赖包含了junit,并且版本号是父pom.xml里面配置的版本号。
所以,dependencyManagement 其实是为了统一管理版本号,把公用的依赖放到dependencyManagement里面管理,在需要引用该依赖的地方只需要groupId和artifactId即可引用该依赖。避免了版本号不同引发的问题
使用jetty插件运行web项目:
在pom.xml 的build 中添加jetty插件:(版本号自定)
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>${jetty-version}</version>
</plugin>
然后运行命令:mvn jetty:run 即可
貌似如果运行tomcat插件的话,我这里直接运行 mvn tomcat:run 就可以了,没有配置tomcat插件。。。
使用Maven CXF插件根据WSDL生成java类:
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.8</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>src/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>http://xxx?wsdl</wsdl>
<frontEnd>jaxws21</frontEnd>
<faultSerialVersionUID>1</faultSerialVersionUID>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
然后执行 mvn generate-sources 即可在src/cxf目录下生成java类
将项目依赖的jar包的源码下载到目录dependency_src目录,但不解压(以jar格式):
mvn dependency:copy-dependencies -DoutputDirectory=dependency_src -DincludeScope=compile -Dclassifier=sources
将项目依赖的jar包的源码下载到目录dependency_src目录并解压:
mvn dependency:unpack-dependencies -Dclassifier=sources -DfailOnMissingClassifierArtifact=false -DoutputDirectory=dependency_src -DincludeScope=compile
使用jacoco生成测试覆盖率report :
maven tomcat plugin : 在pom.xml中添加Plugin:然后运行:mvn tomcat7:run即可
<build>
<finalName>ssh</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- http port -->
<port>9090</port>
<!-- application path always starts with / -->
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
maven jetty plugin:在pom.xml中添加plugin,然后运行: mvn jetty:run 即可
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<!-- jetty port -->
<port>18080</port>
</connector>
</connectors>
</configuration>
</plugin>
多个module的时候,我们修改了某个module,然后只需要从该module开始build即可,这样就不必要build这个module之前的那些module了:(详细参考)
mvn clean install -rf module-name
parent pom.xml和child pom.xml:
parent pom.xml:
<modules>
<module>my-modules/my-module-1</module>
</modules>
The value of <module> is the relative path from the com.mycompany.app:my-app:1 to com.mycompany.app:my-module:1's POM(可以在链接中搜索这句话)
module的值,是从parent的pom.xml到该module的pom.xml的相对路径
child pom.xml:
<parent>
<groupId>parent-groupId</groupId>
<artifactId>parent-artifactId</artifactId>
<version>parent-version</version>
<relativePath>../../pom.xml</relativePath>
</parent>
relativePath的值,是从该module的pom.xml到parent的pom.xml的相对路径
国内maven 仓库地址:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.home}/conf/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<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
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>D:/Program Files/apache-maven-3.3.1/repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
-->
<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
<!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
</servers>
<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
|-->
<mirrors>
<!-- mirror | Specifies a repository mirror site to use instead of a given
repository. The repository that | this mirror serves has an ID that matches
the mirrorOf element of this mirror. IDs are used | for inheritance and direct
lookup purposes, and must be unique across the set of mirrors. | <mirror>
<id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable
Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url>
</mirror> -->
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>ibiblio</id>
<name>ibiblio</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<!-- profiles
| This is a list of profiles which can be activated in a variety of ways, and which can modify
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
| specific paths and repository locations which allow the build to work in the local environment.
|
| For example, if you have an integration testing plugin - like cactus - that needs to know where
| your Tomcat instance is installed, you can provide a variable here such that the variable is
| dereferenced during the build process to configure the cactus plugin.
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular value for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the POM.
|
|-->
<profiles>
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
-->
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
</profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>
添加log4j slf4j依赖:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
相关推荐
maven的本地仓库jar包,方便那些不能上远程仓库下载的朋友们,这个就是我从中央仓库下载下来的资源,如果有需要的可以下载
比较常用的Jar包,maven比较常用的Jar包不用从中央仓库下载。节省时间
一键删除maven本地仓库中下载错误的jar包资源(以lastUpdated结尾的文档)
将jar包添加到本地maven仓库 将jar包添加到本地maven仓库
达梦数7据库j驱动包及方言包,maven依赖jar包,DM达梦数据库jdbc-jar包dialect方言jar包
将本地jar包上传到maven仓库,刷新仓库后即可使用
比如sqljdbc.jar在Maven中央仓库中找不到,但是我们的maven工程中确实需要这样的一个jar包,那么我们首先需要下载对应版本的sqljdbc.jar包到本地,然后按照以下的命令添加到本地仓库。(ps:前提是你已经下载并配置...
kettle是国外开源的一款ETL集成工具,其最新版8.2版本改为了maven项目,由于其maven仓库下载实在太慢,这里提供了我费了一两天才下载好的依赖包,直接解压放在本地仓库即可。方便好使,好用的给个五星好评。
设置Maven的本地仓库与远程仓库,还是挺简单的,在maven的conf中的setting.xml中配置
maven打包 maven打jar包详细步骤
在项目中,使用maven加载依赖仓库时,有时因为网络卡顿或者配置pom.xml时,若下载不完整就会出现lastUpdated等文件。这些文件占内存,项目加载时耗时较久,有时会报错,需要及时清理。 1、工具作用:清理本地和远程...
借此项目,可将下载的maven的jar包按指定格式修改后,maven批量导入第三方jar包至maven本地库,实现快速的maven自动导入maven本地库(建议需要导入的jar包较多时使用)
JSONObject对象相关的jar包依赖,一共有6个;还有maven环境下管理的jar包
JarsCrawler 爬取阿里maven中央仓库的所有jar包
1、搭建阿里云maven私服仓库 2、本地jar手动上传到阿里云maven私服仓库 3、本地项目通过idea自动上传到阿里云maven私服仓库 4、从阿里云私服仓库拉取maven依赖的jar包
NULL 博文链接:https://ailikes.iteye.com/blog/2229719
一键清理maven仓库中下载失败的依赖包 1.修改path路径,将path路径修改为你的maven仓库存放磁盘的全路径 2.双击运行,即可删除下载失败的jar包 3.运行完毕,按任意键退出即可! 4.正确操作完成退出后,再次打开,会出现...
主要介绍了一键清除maven仓库中下载失败的jar包的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧