- 方式一:dependency 本地 jar包
- 方式二:编译阶段指定外部lib
- 方式三:将外部jar打入本地maven仓库
问题再现:
上次这边朋友问我一个问题,就是他们在pom.xml中的dependency中,看到有一些是<scope>provided</scope>的情况,比如如下:
<dependency> <groupId>com.liferay.portal</groupId> <artifactId>portal-impl</artifactId> <version>6.1.0</version> <scope>provided</scope> </dependency>
简单的说,maven-assembly-plugin 就是用来帮助打包用的,比如说打出一个什么类型的包,包里包括哪些内容等等。
内置属性
主要有两个常用内置属性:${basedir}
项目的根目录(包含pom.xml文件的目录),${version}
项目版本
在执行 mvn clean test
时报错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project hello: Compilation failure: Compilation failure: [ERROR] /D:/mavenWork/src/test/java/com/clc/helloworld/test/TestHelloworld.java:[2,17] 程序包org.junit不存在 [ERROR] /D:/mavenWork/src/test/java/com/clc/helloworld/test/TestHelloworld.java:[4,10] 找不到符号
1、由于默认情况下,根据archetype创建maven项目会从网络下载catalog文件,导致创建maven项目缓慢
Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml
2、解决办法可以设置使用本地catalog文件,在IDEA中设置archetype的使用方式为local;
-DarchetypeCatalog=local
一、无依赖其他任何jar
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.think.TestMain</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build>
maven优势:
- 1. 项目自动化编译部署
http://stackoverflow.com/questions/4701532/force-maven-update
mvn clean install -U
-U means force update of dependencies
配置仓库
在maven的settings.xml文件里的mirrors节点,添加如下子节点:
<mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>https://maven.aliyun.com/repository/public</url> </mirror>