7.Eclipse中创建新Maven项目

本文指导如何使用Eclipse导入Maven项目,构建Hello和HelloFriend项目,然后创建第三个Maven项目MakeFriends,实现与HelloFriend项目的交互。通过在MakeFriends中调用HelloFriend的sayHelloToFriend方法,并在MakeFriendsTest中验证方法正确性,完成项目构建与测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



第一步:首先导入前面命令行建立的两个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中的命令执行即可

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涂作权的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值