We are using MAVEN to build a Web application, and the development environment is ECLIPSE+TOMCAT. The build process is as follows:
1. Tool Preparation
Eclipse: Version for Eclipse 4.2 (Juno Service), installation and configuration of MAVEN plug-in See "M2eclipse Installation and Configuration"
Tomcat: Version apache-tomcat-6.0.37 (i.e. tomcat6.x series, this article is installed in D:\work\tomcat6\apache-tomcat-6.0.37-maven)
2. Build Web Applications
We use Eclipse to build a MAVEN Web project with the following steps:
In Eclispe, click "File"-"New"-"other" and the following interface is displayed:
Select "Maven"-"Manve Project" and click "Next"
Set up the workspace, can be set according to the actual situation of the project, here we choose Eclipse Default Workspace "Use default Workspace location", click "Next"
Use archetype to create a Web project, select GroupID as "Org.apache.maven.archetypes", Artifactid "Maven-archetype-webapp", and version as " RELEASE "Archetype build, click on" Next "
Fill in the basic coordinate information of the component as follows:
Group ID:COM.ROCKCMS//project group ID,ROCKCMS domain name (reverse write)
Artifact id:rockcms-web//ROCKCMS Project group builds unique Id,rockcms-web
Version:1.0.0-snapshot//rockcms Project version number, currently a snapshot 1.0.0 version
Java source package path for Package:com.rockcms.framework.web//rockcms project, named as needed
Click "Finish" to display the Rockcms-web project we created in the Ecliplse navigation bar.
3. Configure Web Engineering
After establishing the Web engineering framework, we need to simply refine it to become a well-structured MAVEN Web project.
1) Complete Catalogue
Make the catalog a standard MAVEN structure, adding the necessary home directories (Src/main/java) and test directories (Src/test/java) to the MAVEN project.
Right-Rockcms_web project, click "Properties", such as
Delete the error source folder, select the wrong folder, click "Remove"
A) Add home directory
Click "Add Folder"
Select "Main", click "Create New Folder" and enter folder name "Java". Click "Finish" to complete the creation of the main directory.
In the SRC directory, create the Test/java directory, select "src", click "Create New Folder" and enter folder name "Test/java". Click "Finish" to complete the setup of the test catalog.
2) Configure the class output path
Like standard Web Engineering, we compile the main program into the Web-inf\classes directory, the test program does not need to be packaged, so the test program is compiled or compiled into the target directory. The settings are as follows:
For the sake of convenience, we will compile the default directory to Web-inf\classe, click "Default output Folder" after "Browser", note because Web-inf path in the src source directory, so "Allow output Folders for source Folders "must be checked.
There is no classes directory, you can create a classes directory under the Web-inf directory with "Create New Folder" and click "OK" to complete the configuration, as shown in:
After the default directory is set, we select the compilation location for Sourcefolder, and set the compiled output of Src/main/java.
Select the compiled output of Src/main/java and click "Edit"
Select the project's default output path (project ' defaults output folder) and click "OK"
Similarly, the output path of the src/main/resources is also set to the default path project's default output folder, as shown in the results:
Since test does not need to be packaged into the project, we output the test to the target directory, setting the Src/test/java's compiled output path
Select the specified output path "test-classes" for test and click "OK" to complete the test output path setting.
This step is important to affect the contents of the published war package, if you do not set the compilation path under the main directory to web-inf/classes, the war will not have compiled classes, this example will not be published under Tomcat Run, of course, Follow-up if all classes and resources for this project are made into jars and added to the dependencies of this project, there will be no problem.
3) Configuring the JDK version
Because this project is jdk1.6, the JRE System library needs to be set jdk1.6
4) Adjust the source directory structure order
In order to better show the source code structure, you can adjust the source code in the Eclipse display order, the Src/main/java moved to the top
Click "OK" to close the property interface when you are finished setting.
After the above four steps have been set up, MAVEN's Rockcms-web project is completed.
4. HelloWorld Code
We will revise the contents of index.jsp so as to indicate the following:
5. Use Tomcat to run the Web project
1) Eclipse Configuration Tomcat
Configure Tomcat in eclipse so that Maven can start the Web project with the configured Tomcat. How to configure:
Click "Windows"-"Preferences" to display the window in the
Choose tomcat for configuration, version version6.x, select apache-tomcat-6.0.37 location,
such as: D:\work\tomcat6\apache-tomcat-6.0.37-maven
Save your configuration to complete the configuration of Eclipse and Tomcat.
2) Simplify Maven's Tomcat Run command
To simplify Maven's Tomcat run commands (for example: Tomcat6:run), we need to configure a server in the Maven Setting.xml file as follows:
1 2 3 ) 4 5 |
< server > < id >tomcat6</ id > < username >admin</ username > < password >admin</ password > </ server > |
The server's ID is "TOMCAT6", and as the command line key, because the server configuration requires that we specify the account number and password that the link is taking remotely, we are configuring Tomcat's username and password (for example: admin).
Next we configure the user name and password required for Tomcat configuration, edit the Tomcat-users.xml profile (this article default tomcat is already installed, the installation path is D:\work\tomcat6\ Apache-tomcat-6.0.37-maven. The Tomcat-users.xml file is located in the "\conf" Directory of the Tomcat installation directory, and the user admin for the manager role is added as follows:
<user username= "admin" password= "admin" roles= "manager"/>
Note: The username and password here are consistent with the server user name and password in MAVEN settings.
Start Tomcat (D:\work\tomcat6\apache-tomcat-6.0.37-maven\bin\startup.bat, where Tomcat is configured with a port number of 8080) and access "HTTP// 127.0.0.1:8081/manager/html "address, such as
Enter the user name and password to see if this user is able to access, display the following interface instructions to log in successfully
3) Adding a Tomcat plugin for Web engineering
In order to enable the project to run in the Tomcat container, we need to build the Tomcat plug-in for the project in Pom.xml, where we use the Org.apache.tomcat.maven:tomcat6-maven-plugin : 2.1:release implementation of Web engineering. Tomcat6-maven-plugin is configured in Pom.xml as follows:
The following is a detailed description of the Tomcat plug-in configuration:
1 2 3 4 5 6 7 8 9 Ten One A - - the - - |
< build > < finalName >rockcms-web</ finalName > < plugins > < plugin > < groupId >org.apache.tomcat.maven</ groupId > < artifactId >tomcat6-maven-plugin</ artifactId > < version >2.1</ version > < configuration > < url >http://127.0.0.1:8081/manager</ url > < server >tomcat6</ server > < port >8081</ port > < path >/rockcms</ path > < charset >utf-8</ charset > </ configuration > </ plugin > </ plugins > </ build > |
Specify the configuration of the Tomcat plugin as follows:
Url:tomcat Management app Access path for Tomcat links
Server: Used to obtain the permissions information for MAVEN's remote access configuration in setting, such as user name and password, "Tomcat6" is consistent with the ServerID previously configured in Settings.xml.
Port: Port number, 8081
Webpath path to the Path:rockcms-web project
CharSet: Character Set, Utf-8
4) Start Tomcat to run the Web project
Use the MAVEN command in Eclipse to start Tomcat, run Web engineering, and configure the following methods:
Click "Run"-"Debug configurations. ", such as:
Add a debug command at Maven Build, as follows:
Name: The debug command name, which can be a project name or other
Base Direcory: Runs the project location, which can be passed "Browser Workspace. ", select the project in the current workspace, here is the Rockcms-web project.
Goals: the command executed, Tomcat6:run, here is the simplified command name, which is why you should configure the server.
Click the "Debug" button and the console window in eclipse will display the startup information.
On the first boot, MAVEN will download the Tomcat plugin, which may take a while, and subsequent reboots will not be downloaded and will be faster. After successful startup, access to "http://127.0.0.1:8081/rockcms/" will show the HelloWorld interface we modified.
The above content is to build MAVEN's Web project in Eclipse, and to run the Web project with Tomcat in Eclipse, the configuration is much more, but once the environment is set up, the workload of subsequent build and release will be greatly reduced.
For developers, we already have a standard development environment for Eclipse+tomcat+web, and the next step is to write the program and debug it.