IntelliJ IDEA中的Java项目文件夹结构 [英] Java project folder structure in IntelliJ IDEA

查看:855
本文介绍了IntelliJ IDEA中的Java项目文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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).

为此,您需要:

  1. 转到您的项目结构设置:File > Project Structure
  2. 在中间面板中选择您的项目
  3. 在右侧面板中选择来源"标签
    • 注意(来自@Line):在IntelliJ 2018.3.5中,您选择左侧面板中的'modules'选项卡".
  1. Go to your project structure settings: File > Project Structure
  2. Select your project in the middle panel
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆