The difference between creating Package/folder Source/folder in Eclipse

Source: Internet
Author: User

First of all, Folder,source Folder,package is a folder, since it is a folder, then any file can go to these three kinds of folders below the place.
1. The difference between them
folder is a normal directory, and it doesn't have any difference from the folder we use under Window
The source folder is a special folder, if you use object-oriented thinking to see the source folder, then he is a subset of folder, as a subset, it must have all the functions of the folder, but also has its own special features, his special place, Is the Java file under the source folder will be compiled, the compiled file will be placed under a folder we set (generally we set to web-inf/classes), source The non-Java files below the folder will be copied to the folders under our settings.
The package folder is also a special folder, and what is special about him is that he must exist under the source folder, and the hierarchy is passed by. To differentiate, his path finally consists of each class's packet path name
2. Their role
Folders is the most common folder, and any files you want to put under eclipse can be placed under folder

Source folder is designed to be used to put the Java files to be compiled, because the Java file to be compiled first, then there is a problem, then the folder can be compiled. The folder below cannot be compiled. So design a special folder called the source, the Java file below him can be compiled, and, you can use a certain configuration to put the compiled files under the folder you configured

Package, designed to give Java files to subcontract, plainly, is to manage Java files, if the source folder as a building, then we are through the package of the building into different floors, different rooms, Different floors different rooms we used to do different things, the room put a lot of Java class, one thing to note is that the final package made up a path name, this path name is not a physical path, but Java, there are many times, is the package with the path name, such as: Web.xml,spring.xml and many other configurations

Conversion of 3.package,source Folder,folder to each other
Package turns into folder display: Select Package, Build path-> Exclude
Folder turns into package display: Select folder, Build path-> Include

Package turns to source folder display: Select Package, build path-> use as source folder
source folder turns into package display: Select folder, Build path-> Remove from BuildPath

Conversion of Pacage to source folder ibid.

If you create a source folder, the differences that the project will show in eclipse, such as creating a source folder when testing a class, will distinguish it from the project's directory

The new source folder also causes path problems:
The source folder is the path to the class file in Eclipse, and the src that everyone is familiar with is the source folder.

When we publish the program, the. java files below Src are compiled into a. class file under the Web-inf\classes folder.

You can also build a source folder with a name, but remember that the content in it was eventually released under the Web-inf\classes folder.

This is not what I want to say, I want to say is the path problem.

For example, you build a source Folder called Cong, which contains some configuration files, and when other configuration files refer to Conf,

The path is web-inf\classes. That is, the path to the Conf inside is the SRC path.

You can check that after the program is published, the contents of conf and SRC are placed in a piece, and there is no conf this folder.

* * So we can think: New source folder, in fact, there is no new source folder, visually we feel a lot of a folder,
It's so good to manage our stuff, but finally it's inside something and a piece of stuff under SRC is put. We think all the source folder is a src.
So the path problem is handled according to the SRC path. (You can totally ignore your new source Folder). * *

Note that the Source folder can only be placed in the. java file, which is compiled into a class file at the end of the web-inf\classes.

Of course you can put other files, such as XML files, above I also said that these files and. java files are placed under Web-inf\classes.

The difference is that if you put a. java file, you can build the package. (If you built the folder it automatically becomes the package, because it is intended to put Java files)

Java under the package can be compiled and published at the time of publication. But other formats can only be placed under the source folder, if you put it under a package,

Eclipse did not know, and finally did not publish the file. You can go to the server to see, but there is no file you want. So for other formats of files to be placed in the

Under Source folder, do not create a two level directory, Eclipse does not know. It only knows the Java files within the package directory.

Having said so much, we have a clear idea of the source folder, which was originally designed for Java files, like the package.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.