赞
踩
解压到文件目录下
conf/settings.xml
仓库路径默认目录地址,可修改
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
maven默认服务器修改为阿里云服务器
<mirrors>
<!-- 阿里云仓库 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
mvn compile
mvn clean
mvn test
mvn package
mvn install
maven 组合命令
创建两个项目maventest1 和maventest2
在项目maventest1中创建UserService类
package com.gwl.service;
public class UserService {
public void saveById(int id) {
System.out.println("UserService saveById");
}
}
项目maventest1执行mvn install
cd /Users/mac/Desktop/maventest1
mvn install
项目maventest2的pom.xml 文件添加
<dependencies>
<dependency>
<groupId>com.gwl</groupId>
<artifactId>maventest1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
在项目maventest2中即可使用项目maventest1中的UserService类
package com.gwl.test;
import com.gwl.service.UserService;
public class Demo {
public static void main(String[] args) {
UserService service = new UserService();
service.saveById(1);
}
}
如果无法引用UserService类,则右键 pom.xml 重新 Reimport
配置maven
项目创建成功后的目录结构
打开 Project Structure ,选择Module,点击 Crete Artifact
出现 Artifact,保存
添加tomcat,点击fix,保存
<properties>
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
转载于:https://my.oschina.net/gwlCode/blog/3041358
8
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。