「MAVEN」- 仓库及设置

在 pom.xml 中,添加多个仓库

Setting up Multiple Repositories

其实并不复杂,下面是我们复制过来的:

<project>
<!-- ... -->
  <repositories>
    <repository>
      <id>my-repo1</id>
      <name>your custom repo</name>
      <url>http://jarsm2.dyndns.dk</url>
    </repository>
    <repository>
      <id>my-repo2</id>
      <name>your custom repo</name>
      <url>http://jarsm2.dyndns.dk</url>
    </repository>
  </repositories>
<!-- ... -->
</project>

附加说明:
还以在「Super POM」中定义,也能够在${user.home}/.m2/settings.xml中定义;
这里不再展开,可以参考「Setting up Multiple Repositories」手册;

常用仓库

# 官方仓库 https://mvnrepository.com/

# 阿里云镜像
http://maven.aliyun.com/nexus/content/repositories/snapshots/ (不支持浏览)
https://maven.aliyun.com/mvn/view (仅用作浏览)

# 私有仓库
– 如果你使用 Nexus 搭建了私有仓库,在「Repository Path」列显示的是地址;

HTTP Proxy

参考 Maven – Guide to using proxies 文档,以获取配置代理的方法;

配置文件位置

Apache/Maven/Settings Reference

The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml

# 打包时跳过指定项目

How do I exclude certain modules from a Maven build using the commandline

Maven 3.2.1+
打包时使用选项:-pl "!<modulename>,!<modulename2>"

指定 Main-Class 入口

默认打包生成的 Jar 不能直接运行,因为带有 main 方法的类信息不会添加到 manifest 中(.jar/META-INF/MANIFEST.MF);

需要借助 maven-shade-plugin 实现:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
		<transformers>
			<transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer">
				<mainClass>com.mycompany.app.App</mainClass>
			</transformer>
		</transformers>
    </configuration>
</plugin>