Now that you have the necessary infrastructure in place, the most critical tool for Eclipse is introduced, and the next step is to introduce how to use the tool for code writing.
The previous blog post has been a long time, this time in the company's operating system switch to Fedora 22, I have to say that eclipse in the above interface is a bit ugly, but in general or on the Windows is the same, forget, pull away ...
Here's a look at the process of using eclipse to create SE and EE projects, not involving Maven and git, just familiarity with Eclipse's use.
First said the SE after the EE, the creation of the project behind the blog will also use, run out of panic to delete.
0. Prerequisites
Let's assume that we've already set up the environment for the previous article, and have some idea of what the Eclipse view is, in short, you've seen the previous article.
1. Enter the selection window to create the project
Using Eclipse's Create Project Wizard to create a project, you first need to go to the Project Type Selection window, which is a necessary step for creating all types of projects.
In Project view, project, right-click New, open the Select window for the new project type, and start the first step in creating a new project.
2. Create Java SE Project
In the pop-up selection window, below is a tree menu, expand "Java", locate the "Java Project", and then click "Next".
Then formally into the wizard to create a Java SE project, there are many like configuration can be selected or modified, we are directly using the default, only the name of the project we specify, eclipse will directly use the project name to create a folder to hold the file about this project, so this name we still get "Normal" point, do not take some very "alternative" name, the most important thing is not to violate the folder name character restrictions.
Here I use "testjse" to name this project, and then directly use the default values to complete the wizard.
3. Description of the Java SE Project structure created by eclipse
After the completion of the project structure is this:
Very simple, the SRC folder is used to store Java source files and configuration files, the other is the JRE environment.
SRC below is the direct classpath, we want to write the class, interface, configuration files and so on, to use in the program resources are put here. (not very rigorous, but presumably this understanding)
The JRE Needless to say, the libraries we usually need to introduce are all from here.
4. Write a simple test class
In SRC, right-click "New" and "class", the new Class dialog box pops up.
In the dialog box, fill in the package name, the class name, and the class that needs to be inherited, the implemented interface, and the method that is added by default. We do not specify inherited classes and implemented interfaces here, only the dog choose one to add the main method, easy to run directly.
In the main method, enter "Syso" and then use the code completion of the shortcut key "alt+/" completion, this feature in the previous version of the code will be directly modified here to:
System.out.println ();
But now you need to choose:
Just enter to confirm the line directly.
We enter one of the most common statements-"Hello world".
public static void Main (string[] args) {System.out.println ("Hello World"); }
And then it's running the test class. On this class file or the edit area right-click "Run as", "Java application", you can see the results of the run in the console view.
5. Create a Java Web project
In the box above, select "Dynamic Web Project" in "Web" in the Choose New Project Type window.
Then enter the project name in the next window, select the running environment or whatever, and we'll use the default as well.
Then the next step is good, and next is the next step.
Then the window that appears needs to specify the access root path, the directory name used in the project to hold the deployment file, whether to create Web. XML, and here I choose to create the other default for Web. Xml.
6. Java EE Engineering Structure Description
The effect of creating a good Java EE project in Project view is this:
The SRC directory and the SRC in the SE project are the same;
Libraries inside is the various libraries that the project can use, "Apache Tomcat ..." is from our associated Tomcat library, the JRE Needless to say, and the SE project is the same, "Web App Libraries" is from the project deployment directory " WebContent "Web-inf" inside the "Lib" directory, the jar placed in the Lib directory will automatically correspond to the face.
The WebContent directory is the resource directory for the deployment, which is the root of the site where the project is deployed. Inside the Web-inf directory is a number of configuration files related, users can not directly access to.
Of course, when spring MVC is developed, it puts almost all of the resources under the Web-inf directory, which is not explained here.
7, the servlet Hello World
Right-click on SRC, "new", "servlet" opens the wizard dialog for the new servlet
Fill in the name of the package and class in the dialog box
There is also the option to set the access map path, override the parent class method, description, and so on, directly default!
In the Servers view, select the previously configured Tomcat, right-click, Add and remove to open the Deployment dialog box
will be deployed on the left to the project "ADD" to the right, click on the confirmation is finished
After selecting the server instance in the Servers view, click Start Server in the upper right corner of the attempt
When the console output starts successfully, you can open the browser to access the
At the time of access, the root directory is the project name by default, then the name of the servlet, the port is 8080 by default, and in my case the address is:
Http://127.0.0.1:8080/TestJEE/TestServlet
The effect of access is:
Other specific functions, effects are not the scope of this article to discuss.
8. Summary
This article describes the process of using eclipse to create a new Java SE and Java EE project, the process view structure, the new class, and so on, but does not describe the other options in the specific new process, because this part of the content is not very important because it is managed using MAVEN. The need for the content will be highlighted later when using MAVEN, the technical aspect of coding is not within the scope of this series, so just to mention how to create a new class.
The new project mentioned in this article is very good when using Eclipse, the file directory structure is simple and clear, but is not in line with the MAVEN project default directory structure, the focus of this series will be placed in accordance with the MAVEN default file structure of the project, So the next article will describe the MAVEN default directory structure and how to create a new structure that works.
The new project here is not to be deleted, but will be used later.
People think there is something wrong place also please leave a message. at the same time, we feel useful, please also leave a message to encourage.
enjoy!!
Using Eclipse-maven-git to do Java Development (5)--eclipse Java project creation process