使用【IDEA】【Maven】创建不同module之间的调用

先直接上手:

创建空的项目:
在这里插入图片描述
根据提示,创建新的module,也可以先进入项目在创建module
在这里插入图片描述
创建Maven项目,直接next,输入对应的 groupId,artifactId
在创建一个module,结果如下所示:
在这里插入图片描述
展开目录。test模块引用testSon模块。

test的pom文件如下

<?xml version="1.0" encoding="UTF-8"?>
<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.test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>com.test</groupId>
            <artifactId>testSon</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

testSon的pom

<?xml version="1.0" encoding="UTF-8"?>
<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.test</groupId>
    <artifactId>testSon</artifactId>
    <version>1.0-SNAPSHOT</version>
</project>

testSon下创建Dog类

public class Dog {
    public void call(String s){
        System.out.println("wwwww"+s);
    }
}

test下创建Animal调用


public class Animal {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.call("狗叫");
    }
}

然后启动,可能会遇到的问题

1、IDEA中提示:Warning:java: 源值1.5已过时, 将在未来所有发行版中删除

2、Cannot start process, the working directory ‘F:\test\hello’ does not exist

问题一解决:

打开项目配置(默认快捷键:ctrl+shift+alt+s):
在这里插入图片描述
在这里插入图片描述
打开【File】—【Settings】,找到【Java Compiler】
在这里插入图片描述
点击Apply—OK

问题二解决:
在这里插入图片描述
点击Apply—OK

之后你可能还会遇到版本问题(原因我也不知道。。。)。然后按照问题一的解决方式重新配置一下。(可能因为配置步骤,它有回到1.5了。)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值