IntelliJ IDEA中的Java项目文件夹结构 [英] Java project folder structure in IntelliJ IDEA
问题描述
IntelliJ IDEA中Java项目可接受的文件夹结构是什么?
What is an acceptable folder structure for Java projects in IntelliJ IDEA?
多个来源(类似)建议采用以下结构:
Multiple sources (like this) suggest the following structure:
.
│ .idea
└── src
├── main
│ ├── java
│ │ └── com.simpleproject
│ │ └── SimpleClass.java
│ └── resources
└── test
├── java
│ └── com.simpleproject
│ └── SimpleClassTest.java
└── resources
我知道这以前是可行的,但现在它在抱怨java.lang.SecurityException: Prohibited package name: java
I know this has worked before, but right now it is complaining java.lang.SecurityException: Prohibited package name: java
显然,java
不允许作为软件包名称.我不明白为什么有时候可以接受,有时又不能接受.有人可以在IntelliJ IDEA的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?
推荐答案
这是Maven项目的基本文件夹结构. IntelliJ通常会识别出这种情况并为您设置合理的默认值.
That is the basic folder structure of a maven project. IntelliJ usually recognizes this and sets up sensical defaults for you.
如果没有(或者确实有,但是您随后对其进行了修改),则需要将Java文件夹设置为sources
文件夹(即包含源代码的文件夹).
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).
为此,您需要:
- 转到您的项目结构设置:
File > Project Structure
- 在中间面板中选择您的项目
- 在右侧面板中选择来源"标签
- 注意(来自@Line):在IntelliJ 2018.3.5中,您选择左侧面板中的'modules'选项卡".
- Go to your project structure settings:
File > Project Structure
- Select your project in the middle panel
- Select the 'sources' tab in the right panel
- Note from a comment (thanks @Line): In IntelliJ 2018.3.5, you "select 'modules' tab in left panel".
重复测试文件夹(标记为"Tests"),资源(标记为"Resources"),测试资源(标记为"Test Resources")等.
Repeat for test folder (mark as 'Tests'), resources (mark as 'Resources'), test-resources (mark as 'Test Resources'), etc.
这篇关于IntelliJ IDEA中的Java项目文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!