7.Eclipse中创建新Maven项目



第一步:首先导入前面命令行建立的两个maven项目HelloHelloFriend

      方法:选择file-->import-->Existing MAVEN PROJECTS选项选择对应项目路径导入即可

 

第二步:按顺序先后执行HelloHelloFriend项目的的构建

      方法:右击各自项目pom.xml文件,选择run as中的maveninstall命令将构件安装至仓库中

 

第三步:通过eclipse新建第三个maven项目。选择file-->new-->other-->MAVENPROJECT选项

 

第四步:在src/main/java中新建文件cn.toto.maven.MakeFriends.java

 

package cn.toto.maven;

 

public class MakeFriends {

 

   public StringmakeFriends(String name){

      

      HelloFriendfriend = new HelloFriend();

      friend.sayHelloToFriend("litingwei"); 

      String str= "Hey,"+friend.getMyName()+" make a friend please.";

      System.out.println(str);

      returnstr;

   }

}

 

第五步:在src/test/java中新建文件cn.toto.maven.MakeFriendsTest.java

 

package cn.toto.maven;

 

import static junit.framework.Assert.assertEquals;

import static org.junit.Assert.*;

 

import org.junit.Test;

 

public class MakeFriendsTest {

 

   @Test

   public voidtestMakeFriends(){    

      MakeFriendsmakeFriend = new MakeFriends();

      String str= makeFriend.makeFriends("tuzuoquan");

      assertEquals("Hey,Johnmake a friend please.",str);    

 

   }

}

 

第六步:点击根目录pom.xml添加依赖

 

    <dependencies>

      <dependency>

          <groupId>junit</groupId>

          <artifactId>junit</artifactId>

          <version>4.9</version>

          <scope>test</scope>

      </dependency>

      <dependency>

           <groupId>cn.toto.maven</groupId>

           <artifactId>HelloFriend</artifactId>

           <version>0.0.1-SNAPSHOT</version>

           <type>jar</type>

           <scope>compile</scope>

     </dependency>

 

    </dependencies>

 

第七步:右击pom.xml选择run as中的命令执行即可

 

 

上一篇:java-工具-*


下一篇:阿里云 Centos8 报错“Error: Failed to synchronize cache for repo 'epel-modular'”解决方案