Directory structure of a MAVEN project in eclipse

Source: Internet
Author: User

In the previous Javase development, not very concerned about the Eclipse Engineering directory environment, always see a src on the point to create a new package and then write a class. In the days to come, there is no chance to notice how a project is organized and how to control it.

But recently, when learning about Maven, I learned that it had a requirement for the directory structure of the project, the so-called "formula is better than the configuration". The directory structure of a Java project that is recognized by the vast majority of people is determined. This unifies the various complex configuration projects on the market. So I began to look at the information to see how others actually arranged a good engineering framework.

First, the directory structure of a default Eclipse project:

MyProject: The name of the project

SRC: A source file folder, official saying: "Source folder on Build path". Inside the most put is the source code, in the javase inside, often is to put the package directly in the SRC directory.

Com.jd.MyProject: a package. The domain name is typically inverted to ensure its uniqueness.

Main.java: a Java file.

That's all it looks like? In fact, in my Mac environment, the directory on the left of Eclipse is usually the package Explorer, which is also the content shown. But you can actually show the real directory with another one, which includes some hidden files. Called Navigator. The display results are as follows:

Thus, if the name of the package is passed. Connection, its effect on physical storage is to generate hierarchy folder, Com.jd.MyProject---->com/jd/myproject.

The bin directory is the place where the compiled class file is stored, of course, the general Eclispe every time the save will be automatically compiled, programmers generally do not have to be too much of the results of compiling, so in the most commonly used package Explorer does not display this bin folder.

Second, there are some more files.

The file under the 1,.settings folder: Org.eclipse.jdt.core.prefs. The contents are:

1Eclipse.preferences.version=12Org.eclipse.jdt.core.compiler.codegen.inlinejsrbytecode=enabled3org.eclipse.jdt.core.compiler.codegen.targetplatform=1.84Org.eclipse.jdt.core.compiler.codegen.unusedlocal=Preserve5org.eclipse.jdt.core.compiler.compliance=1.86Org.eclipse.jdt.core.compiler.debug.linenumber=Generate7org.eclipse.jdt.core.compiler.debug.localvariable=Generate8org.eclipse.jdt.core.compiler.debug.sourcefile=Generate9Org.eclipse.jdt.core.compiler.problem.assertidentifier=ErrorTenOrg.eclipse.jdt.core.compiler.problem.enumidentifier=Error Oneorg.eclipse.jdt.core.compiler.source=1.8

It is clear that the JDK is clear and there are some compiler parameters to configure.

2,.classpath. The contents of this hidden file are:

1 <?xml version= "1.0" encoding= "UTF-8"?>2 <classpath>3     < Classpathentry kind= "src" path= "src"/>4     <classpathentry kind= "Con"5         path= " org.eclipse.jdt.launching.jre_container/org.eclipse.jdt.internal.debug.ui.launcher.standardvmtype/javase-1.8 "/ >6     <classpathentry kind= "Output" path= "Bin"/>7 </classpath>

This is important because the file directly controls the directory structure of a project. The kind property is SRC, which indicates that this folder is the source folder and the physical location is/SRC. That's the folder we saw.

The kind property is con, which is the config, which controls the jvm,jdk of the project, and so on, a change that we don't need. The kind property is output, which shows that the generated class file is placed in the physical address:/bin.

Seeing the configuration of this file, we know why the directory arrangement for the project is that way, in other words, it is the configuration of this file, the project only manifests that kind of directory. Further, if you configure the file in accordance with your ideas, then after you save the project directory structure will automatically become the way you arranged.

3,project. The contents are as follows:

1<?xml version= "1.0" encoding= "UTF-8"?>2<projectDescription>3<name>MyProject</name>4<comment></comment>5<projects>6</projects>7<buildSpec>8<buildCommand>9<name>org.eclipse.jdt.core.javabuilder</name>Ten<arguments> One</arguments> A</buildCommand> -</buildSpec> -<natures> the<nature>org.eclipse.jdt.core.javanature</nature> -</natures> -</projectDescription>

There are also some configuration files about compiling, and here's what Maven will talk about.

The above is a common Java project all the files and their directory structure, you can see in my previous writing code without careful attention to the place, some configuration files on the structure of the project constraints.

Next is a MAVEN project.

The directory structure you see in the Package Explorer is:

A closer look at this directory structure is not the same as the most common javase. First of all its source folder has two: Src/main/java and Src/test/java. Note under the SRC folder, there are two branches of main and test. In short, main is the factory subject, including various source code resources and so on, and Test contains the tests and resources. The reason is that the test code does not need to be packaged for publishing. and two folders inside the package, still as before, according to the name of the inverted domain naming specification to name.

Several different points:

1, there is a target folder, very simple, is the source code compiled after the creation of the class file place. The placement of class files is also distinguished by the project code or the test code.

2, a pom.xml. This file can be said to be a MAVEN project's most important file, because this is MAVEN's basic configuration file, and the programmer to deal with the most also in this file, including configuration dependencies and so on.

Then look at the file structure under Navigator:

Some of these files are more repetitive, such as: Src/test and target/test-classes do not open.

Here are the changes:

1,.settings, this I have not very serious research, can guess the more part of Maven is some of the configuration, such as JDK version and file encoding format (UTF-8) and so on.

2,.classpath, the contents of this file have changed:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Classpath>3     <ClasspathentryKind= "src"Output= "Target/classes"Path= "Src/main/java">4         <attributes>5             <attributename= "Optional"value= "true" />6             <attributename= "Maven.pomderived"value= "true" />7         </attributes>8     </Classpathentry>9     <ClasspathentryKind= "src"Output= "Target/test-classes"Ten Path= "Src/test/java"> One         <attributes> A             <attributename= "Optional"value= "true" /> -             <attributename= "Maven.pomderived"value= "true" /> -         </attributes> the     </Classpathentry> -     <ClasspathentryKind= "Con" - Path= "org.eclipse.jdt.launching.jre_container/org.eclipse.jdt.internal.debug.ui.launcher.standardvmtype/ j2se-1.5 "> -         <attributes> +             <attributename= "Maven.pomderived"value= "true" /> -         </attributes> +     </Classpathentry> A     <ClasspathentryKind= "Con" at Path= "Org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> -         <attributes> -             <attributename= "Maven.pomderived"value= "true" /> -         </attributes> -     </Classpathentry> -     <ClasspathentryKind= "Output"Path= "Target/classes" /> in </Classpath>

Previously said that this file is used to configure the directory structure of the project, you can see that it is the configuration of this file, so that the project in eclipse reflected in the same directory structure. The specific point is that it re-defined a variety of documents (source, configuration, output) in the project storage directory. There are a few more configuration parameters, but no need to move.

3,.project.xml

This document can be said to be the most important, because at first I thought the question is: how to transform a common Javase project into a maven project, I changed a little, finally found the most critical point, is in this file. The contents of the file are as follows:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <projectdescription>3     <name>Mavendemo</name>4     <Comment></Comment>5     <Projects>6     </Projects>7     <Buildspec>8         <Buildcommand>9             <name>Org.eclipse.jdt.core.javabuilder</name>Ten             <arguments> One             </arguments> A         </Buildcommand> -         <Buildcommand> -             <name>Org.eclipse.m2e.core.maven2Builder</name> the             <arguments> -             </arguments> -         </Buildcommand> -     </Buildspec> +     <Natures> -         <Nature>Org.eclipse.jdt.core.javanature</Nature> +         <Nature>Org.eclipse.m2e.core.maven2Nature</Nature> A     </Natures> at </projectdescription>

You can see two more lines. One inside the Buildcommand tag, one inside the natures tag. If you're in a normal Javase project, you've added

<nature>org.eclipse.m2e.core.maven2Nature</nature>

You can see that eclipse will add an M to the project icon to identify it as a MAVEN project. Delete this sentence and then save, the previous words will be automatically deleted. This statement is the key to determining the "characteristics" of the project.

These are the differences between the engineering structures of MAVEN and general engineering.

Directory structure for a MAVEN project in Eclipse

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.