创建maven工程

maven工程结构

Project

|--src(源码包)

|--main(正常的源码包)

|--java(.java文件的目录)

|--resources(资源文件的目录)

|--test(测试的源码包)

|--java

|--resources

|--target(class文件、报告等信息存储的地方)

|--pom.xml(maven工程的描述文件)


创建maven工程

eclipse mars 4.5.0版本自带maven插件


通过骨架创建

file——》new Maven Project——》maven-archetype-quickstart


MavenFirst.java

package com.wxh.maven;

public class MavenFirst {

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


TestMavenFirst.java
package com.wxh.maven;

import org.junit.Test;

import junit.framework.Assert;

public class TestMavenFirst {

	@Test
	public void testSayHello(){
		MavenFirst mf=new MavenFirst();
		String result=mf.sayHello("maven");		
		Assert.assertEquals("hello maven", result);
	}
}

pom.xml自动配好了



跳过骨架选择

file——》new Maven Project——》(勾选上 create a simple project)

有三种打包方式可供选择:jar,war,pom

MavenSecond.java

package com.wxh.maven;

public class MavenSecond {

	public String sayHello(String name){
		
		MavenFirst first=new MavenFirst();
		
		return first.sayHello(name);
		
	}
}

引用了第一个工程中的类,可能不能编译,clean一下工程就行了。

通过配置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.wxh.maven</groupId>
  <artifactId>MavenSecond</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
<dependencies>
	<dependency>
		<groupId>com.wxh.maven</groupId>
		<artifactId>MavenFirst</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</dependency>
	
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.9</version>
	</dependency>
</dependencies> 
  
</project>


TestMavenSecond.java
package com.wxh.maven;

import org.junit.Test;

import junit.framework.Assert;

public class TestMavenSecond {

	@Test
	public void sayHello(){
		
		MavenSecond second=new MavenSecond();
		
		String result=second.sayHello("wxh");;
		
		Assert.assertEquals("wxh", result);
		
	}
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值