软件包结构应与Java中的目录结构“始终”相同 [英] Package structure should be same as directory structure in Java "always"?

查看:110
本文介绍了软件包结构应与Java中的目录结构“始终”相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

软件包结构应该与Java中的目录结构相同。
我试图浏览Oracle Java文档的正式文档,但无处可以找到这个规则。



这个规则是否扩展到其他IDE,如Netbeans或是这是Java语言本身的规则吗?
这个规则有多严格,可以偏离,为什么会这样做?

解决方案

JLS 作为规则,编译器可能 require:


存储在文件系统中的包可能对其编译单元的组织有一定限制,以允许简单


例如,如果您在javac的命令行中指定了所有源文件名,那么您不需要

注意,默认情况下,javac将生成类文件作为源文件的对等体,而不管包结构如何;如果您指定 -d ,它将生成适当的输出结构,即使它与源结构不匹配。


Package structure should be same as directory structure in Java it seems in Eclipse. I tried to browse through the formal documentation on Oracle Java docs but nowhere I could find this rule

Does this rule extend to other IDEs such as Netbeans or is this a rule of Java language itself? How strict is this rule, can it be deviated from and why was it made?

解决方案

It's specified in the JLS as a rule that compilers may require:

Packages that are stored in a file system may have certain constraints on the organization of their compilation units to allow a simple implementation to find classes easily.

For example, if you specify all the source filenames on the command line for javac, you don't have to follow those rules... but it's pretty much universally used, and I wouldn't dream of violating this rule for anything other than tiny tests.

Note that by default, javac will generate the class file as a peer of the source file, regardless of package structure; if you specify -d it will generate the appropriate output structure even if it doesn't match the source structure.

这篇关于软件包结构应与Java中的目录结构“始终”相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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