小白在初学maven分模块开发项目时遇到的问题(Idea)

1 篇文章 0 订阅
1 篇文章 0 订阅

1、模块之间无法调用相应的属性和方法

        没有添加依赖,如果是依赖父文件,则需要在pom>xml中添加依赖用标签

<parent>
    <artifactId>*****</artifactId>
    <groupId>*****</groupId>
    <version>*****</version>
</parent>

如果是依赖其他模块,则用

<dependency>
    <groupId>*****</groupId>
    <artifactId>*****</artifactId>
    <version>*****</version>
</dependency>

添加依赖前最好先给依赖的模块打包,

2、添加新模块后删除,请记得在父文件pom.xml中把对应的model删除

3、模块变为普通文件夹,可能是误操作移除了maven项目,只需要重新添加maven项目就好

        Idea进入project structure,

        然后点击Modules,点击+号,

        选择import module,然后找到对应的module所在位置,添加进来。

        pom.xml也适用,可以右键pom文件,最下面有+重新添加为maven文件,点击即可。

注意:maven中jar包是自动加载的,依赖添加到pom.xml中即可,常用的最好自建文件,方便查询和导入

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IDEA 开发环境中,使用 Maven 项目,可以使用 profile 来指定不同的环境。通常情况下,我们会为开发、测试和部署环境创建不同的 profile。具体步骤如下: 1. 在 pom.xml 文件中,添加 profile 标签。 ``` <profiles> <profile> <id>dev</id> <properties> <env>dev</env> </properties> </profile> <profile> <id>test</id> <properties> <env>test</env> </properties> </profile> <profile> <id>prod</id> <properties> <env>prod</env> </properties> </profile> </profiles> ``` 这里我们创建了三个 profile,别对应着 dev、test 和 prod 环境。 2. 在 pom.xml 文件中,添加 build 标签,并在其中引用 profile。 ``` <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>default-copy-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/classes</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 这里我们使用 Maven 插件 maven-resources-plugin,将 src/main/resources 目录中的资源文件复制到 target/classes 目录中,并在复制的过程中进行过滤,替换其中的占位符。 3. 在 resources 目录中,创建三个文件夹 dev、test 和 prod,并在其中创建一个名为 application.properties 的文件。 ``` src/main/resources/ ├── dev │ └── application.properties ├── prod │ └── application.properties └── test └── application.properties ``` 这里我们为每个环境创建了一个 application.properties 文件,用于存放该环境的配置信息。 4. 在 application.properties 文件中,添加一些配置信息。 ``` server.port=8080 spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=root ``` 这里我们添加了一些常用的配置信息。 5. 在 IDEA 开发环境中,选择 Edit Configurations,在其中添加一个 Maven 配置。 6. 在 Command line 中输入以下命令: ``` clean install -Pdev ``` 这里的 -P 参数表示指定 profile,这里我们指定了 dev 环境。 7. 点击 OK,保存配置。 现在,我们可以在 dev 环境中运行项目了。如果需要在其他环境中运行项目,只需要更改 Command line 中的 profile 参数即可。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值