Java 如何在 Intellij 中创建 Maven 多模块项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37984402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create Maven Multi Module Project in Intellij?
提问by Aravind E
I am using IntelliJ IDEA Community Edition 2016.1.3. I'm trying to create a maven multi module project. Project company is the parent and Project employee and Project skillset are child modules. Project employee and skillset will have packing as a WAR but Project company has packing as POM.
我正在使用 IntelliJ IDEA 社区版 2016.1.3。我正在尝试创建一个 maven 多模块项目。项目公司是父模块,项目员工和项目技能集是子模块。项目员工和技能组将打包为 WAR,但项目公司将打包为 POM。
my project structure look like this (above), but i need my project structure to be like below image
我的项目结构看起来像这样(上图),但我需要我的项目结构如下图所示
and I could not create a class under employee and skillset. How can I create a multi module project without having src folder in parent (company)?
我无法在员工和技能集下创建课程。如何在父(公司)中没有 src 文件夹的情况下创建多模块项目?
采纳答案by vikingsteve
Your presumption is correct, the top level project being pom
packaging should have no source.
您的假设是正确的,正在pom
打包的顶级项目应该没有来源。
So start by removing (just delete or move elsewhere) the src
folder from the top level (and everything under it... main, java, resources, text...)
因此,首先src
从顶层删除(只需删除或移动到其他地方)文件夹(及其下的所有内容... main、java、resources、text...)
Now, looking at your modules, they look correct. You can test they are configured properly by control-clicking them from the top pom, and they should navigate to the child pom's.
现在,看看你的模块,它们看起来是正确的。您可以通过从顶部 pom 控制单击它们来测试它们是否配置正确,并且它们应该导航到子 pom。
Lastly you want to set up a source structure under the child projects (which have war packaging). Manually create a folder structure under Employee
module src\main\java
, right click it and choose Mark As -> Source Root
.
最后,您要在子项目(具有战争包装)下设置源结构。在Employee
模块下手动创建一个文件夹结构src\main\java
,右键单击它并选择Mark As -> Source Root
.
Do same for SkillSet
and you're done.
做同样的SkillSet
事情,你就完成了。
回答by Mukit09
I know you got your answer. This is for those who are using updated versions.
我知道你得到了答案。这是为那些使用更新版本的人准备的。
I am using Ultimate 2019.1. I had two spring boot projects generated from Spring Initializer. I created a directory where I kept my two sub-project and the parent pom.
我正在使用 Ultimate 2019.1。我有两个从 Spring Initializer 生成的 Spring Boot 项目。我创建了一个目录,在其中保存了我的两个子项目和父 pom。
Then I kept the cursor on /src/main/java of each project, right-click on the Java folder and choose Mark Directory as -> Generated Source Root
.
然后我将光标保持在每个项目的 /src/main/java 上,右键单击 Java 文件夹并选择Mark Directory as -> Generated Source Root
.
These solved my problem.
这些解决了我的问题。