maven--M2Eclipse

9 篇文章 0 订阅

安装M2Eclipse

第一步:将文件拷贝

 

第二步:拷贝到eclipse中的dropins目录

 

第三步:查看eclipse中是否安装成功

第四步:设置maven的安装路径

第五步:设置maven的用户配置

maven-->User Setting-->E:\repo\settings.xml

单独使用命令方式进行maven的使用时,用户配置文件默认在~/.m2/settings.xml

如果使用eclipse,则可以任意指定用户配置文件的地址

 

创建MavenFirst工程

第一步:创建maven工程

第二步:next

 

第三步:next

 

第四步:

指定工程的GAV坐标

 

第五步:点击finish,创建maven工程

第六步:创建MavenFirst.java

package com.hcx.maven;

/**
 * Title: MavenFirst
 */
public class MavenFirst {

	public String sayHello(String name) {
		return "hello " + name;
	}
}
 

第七步:创建TestMavenFirst.java

 

package com.hcx.maven;

import org.junit.Test;

import junit.framework.Assert;

/**
 * <p>Title: TestMavenFirst</p>
 */
public class TestMavenFirst {

	@Test
	public void testSayHello(){
		MavenFirst first = new MavenFirst();
		
		String result = first.sayHello("hm19");
		
		Assert.assertEquals("hello hm19", result);
	}
}
 
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>

  <groupId>com.hcx.maven</groupId>
  <artifactId>MavenFirst</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>MavenFirst</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.9</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
    	<groupId>log4j</groupId>
    	<artifactId>log4j</artifactId>
    	<version>1.2.9</version>
    </dependency>
  </dependencies>
  
  <build>
		<plugins>
			<!-- 编译插件,指定编译用的的jdk版本 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
		</plugins>
	</build>
	
	<distributionManagement>
		<repository>
			<id>releases</id>
			<name>Internal Releases</name>
			<url>http://localhost:8080/nexus-2.7.0-06/content/repositories/releases/</url>
		</repository>
		<snapshotRepository>
			<id>snapshots</id>
			<name>Internal Snapshots</name>
			<url>http://localhost:8080/nexus-2.7.0-06/content/repositories/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>
	
</project>
 

 

第七步:使用eclipse的选项执行maven命令

创建MavenSecond工程

第一步:创建maven工程

第二步:next

 

第三步:next

打包方式jar

 

第四步:finish,创建maven工程

第五步:创建MavenSecond.java

 

package com.hcx.maven;
/**
 * <p>Title: MavenSecond</p>
 * <p>Description: TODO(这里用一句话描述这个类的作用) <p>
 */
public class MavenSecond {
	
	public String sayHello(String name){
		MavenFirst first = new MavenFirst();
		return first.sayHello(name);
	}
}
 

 

第六步:创建TestMavenSecond.java

package com.hcx.maven;

import junit.framework.Assert;

import org.junit.Test;

/**
 * <p>Title: MavenSecond</p>
 */
public class TestMavenSecond {
	
	@Test
	public void sayHello(){
		MavenSecond second = new MavenSecond();
		String result = second.sayHello("hm19");
		
		Assert.assertEquals("hello hm19", result);
	}
}
 
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>
	<groupId>com.hcx.maven</groupId>
	<artifactId>MavenSecond</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<dependencies>
		<dependency>
			<groupId>com.hcx.maven</groupId>
			<artifactId>MavenFirst</artifactId>
			<version>0.0.1-SNAPSHOT</version>
<!-- 			<optional>true</optional> -->
		</dependency>

		<!-- 第二直接依赖 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.7</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.8</version>
		</dependency>
	</dependencies>
</project>

 


 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值