IntelliJ IDEA 中的 Java 项目文件夹结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41638654/
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
Java project folder structure in IntelliJ IDEA
提问by Atte Juvonen
What is an acceptable folder structure for Java projects in IntelliJ IDEA?
IntelliJ IDEA 中 Java 项目可接受的文件夹结构是什么?
Multiple sources (like this) suggest the following structure:
多个来源(像这样)建议采用以下结构:
.
│ .idea
└── src
├── main
│ ├── java
│ │ └── com.simpleproject
│ │ └── SimpleClass.java
│ └── resources
└── test
├── java
│ └── com.simpleproject
│ └── SimpleClassTest.java
└── resources
I know this has worked before, but right now it is complaining java.lang.SecurityException: Prohibited package name: java
我知道这以前有效,但现在它在抱怨 java.lang.SecurityException: Prohibited package name: java
Apparently, java
is not allowed as a package name. I don't understand why it's sometimes acceptable and sometimes not acceptable. Can someone provide a complete example of an acceptable project folder structure in a Java project in IntelliJ IDEA?
显然,java
不允许作为包名。我不明白为什么有时可以接受有时不可以接受。有人可以在 IntelliJ IDEA 的 Java 项目中提供可接受的项目文件夹结构的完整示例吗?
采纳答案by blurfus
That is the basic folder structure of a maven project. IntelliJ usually recognizes this and sets up sensical defaults for you.
这就是 Maven 项目的基本文件夹结构。IntelliJ 通常会识别出这一点并为您设置合理的默认值。
If it didn't (or if it did but you modified them afterwards), you need to set up your java folder as the sources
folder (i.e. the folder that contains the source code).
如果没有(或者如果有,但您后来修改了它们),您需要将您的 java 文件夹设置为sources
文件夹(即包含源代码的文件夹)。
For this, you need to:
为此,您需要:
- Go to your project structure settings:
File > Project Structure
- Select your project in the middle panel
- Select the 'sources' tab in the right panel
- Notefrom a comment (thanks @Line): In IntelliJ 2018.3.5, you "select 'modules' tab in left panel".
- Navigate to the
src/main/java
folder and select it - Mark it as
Sources
- 转到您的项目结构设置:
File > Project Structure
- 在中间面板中选择您的项目
- 在右侧面板中选择“来源”选项卡
- 注意从评论(感谢@Line):在2018年3月5日的IntelliJ,您“选择‘模块’在左边的面板标签”。
- 导航到
src/main/java
文件夹并选择它 - 将其标记为
Sources
Repeat for test folder (mark as 'Tests'), resources (mark as 'Resources'), test-resources (mark as 'Test Resources'), etc.
重复测试文件夹(标记为“测试”)、资源(标记为“资源”)、测试资源(标记为“测试资源”)等。
回答by Umut Uzun
Your configuration in the IntelliJ's File > Project Structure
page will be overridden by the project's pom.xml
after every clean install
. To prevent this, you need to configure the source directory in pom.xml
as below:
您在 IntelliJFile > Project Structure
页面中的配置将pom.xml
在每个clean install
. 为了防止这种情况,您需要配置源目录pom.xml
如下:
<sourceDirectory>src/main/java</sourceDirectory>
回答by Nipuna Don Pranciscu
Simply close intellij and delete any existing .IML file from the project root will do it
只需关闭 intellij 并从项目根目录中删除任何现有的 .IML 文件即可