Maven+eclipse+tomcat Configuration Process Logging

Source: Internet
Author: User
Tags aop character set response code xmlns tomcat log4j

First, set MAVEN's setting file location in Eclipse, point to the MAVEN directory you downloaded, and the warehouse will be generated automatically.


First, create the MAVEN project in Eclipse and note several items:

Select an item with a artifact ID of Maven-archetype-webapp


Second, create the directory structure: Project right key: New-source Folder, create the following directories

1, Src/main/java

2, Src/test/java

3, Src/test/resources


Third, in turn, set the class output directory java,resources directory, project right key: Build Path-source, double-click Source Folder, in the pop-up box to select the output directory.

Also select the Allow output folders for source folders.



Turn project into Dynamic Web project Right key project, select Project Facets, click Convert to faceted from

Configure Project Facets

Select Java and version 1.6, check the version of Dynamic Web module to 2.5. (3.0 for Java7).

If you are prompted for an error, you may need to set the compiler compliance level to 1.6 in the Java compiler.           Or you need to change the Java version of this window to 1.6. Another: If the error cannot ... Dynamic Web Module to 2.5

Open the Org.eclipse.wst.common.project.facet.core.xml file under the. Setting folder under the project root manually modified version

<faceted-project>
<fixed facet= "Wst.jsdt.web"/>
<installed facet= "java" version= "1.6"/>< compiler version 1.6, running JDK versions can not be lower than the compiled version >
<installed facet= "Jst.web" version= "2.5"/><servlet2.5 Edition >
<installed facet= "Wst.jsdt.web" version= "1.0"/>
</faceted-project>

------------------------------------------------the following 4 lines to ignore configuration Modify faceted Project

Click further configuration available ..., eject modify faceted Project window

Here is the path to set the Web.xml file, we enter Src/main/webapp.

Generate Web.xml Deployment descriptor automatically generate Web.xml files, optional. --------------------------------------------------------------

Set up a directory location for file publishing at Project deployment

Open this window in the right key item. A deployment Assembly appears in the list on the left, and when clicked, the following figure:

1, you need to delete the two items of test because test is used and does not need to be deployed.

2, set up the Maven jar package to be published under Lib.

ADD-> Java Build Path Entries-> Maven dependencies-> Finish

To set the effect chart after completion


Vi. adding jar packs to MAVEN projects

6.1 Add the required jar package to the Pom.xml

Using Maven POM Editor to open the Pom.xml file in your project, select dependencies, click Add on the Dependencies column, and first pop up a search button, such as input spring-web, Automatically searches for spring-web-related jar packs, we select the 3.0.5 version of spring. Add the spring package all in. Additional jar packages that need to be added are: JUnit, Jstl. or click Pom.xml to edit the Pom.xml file directly. This can be directly copy over dependencies content.

6.2 Set scope for JAR packs

When adding into a jar package, there are some attributes that need to be set, most importantly scope, which has the following values:

1. Compile, the default value, applies to all phases and is published along with the project.

2. Provided, similar to compile, expects the JDK, container or user to provide this dependency. such as Servlet.jar.

3. Runtime, only used at runtime, such as JDBC driver, applicable to run and test phase.

4. Test, used only during testing, to compile and run the test code. Will not be published with the project.

5. System, similar to provided, needs to explicitly provide a jar,maven that contains dependencies and does not find it in repository.

Typically, the SPRINGMVC project needs to configure the scope of the jar package as shown below:

Sometimes found Servlet-api or was packaged under the Lib, at this time will certainly be an error. You'll need to install the WTP in the Maven plugin as well.

Eclipse Online Installation path: Http://m2eclipse.sonatype.org/sites/m2e-extras. Select for Eclipse WTP.

-------------------------------------------------------------------------------------------------The following constructs the Spring Framework section to ignore VII. Construction of SPRINGMVC framework

7.1 Editing Web.xml files

Need to add log4j, character filtering, Spring dispatcher, and so on.

The Webx.xml code is as follows:

XML code

<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns= "Http://java.sun.com/xml/ns/javaee" HT 
                             Tp://www.w3.org/2001/xmlschema-instance "xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee 
        Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "version=" 2.5 "> <context-param>

    <param-name></param-name> <param-value></param-value> </context-param> <!--Spring's log4j listener--> <listener> &LT;LISTENER-CLASS&GT;ORG.SPRINGFRAMEWORK.WEB.UTIL.LOG4JC Onfiglistener</listener-class> </listener> <!--character Set filter--> <filter> <fil Ter-name>characterencodingfilter</filter-name> <filter-class> Org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <par Am-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>for Ceencoding</param-name> <param-value>true</param-value> </init-param> < /filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <
        Url-pattern>/*</url-pattern> </filter-mapping> <!--Spring View distributor--> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.di Spatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</p Aram-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> &LT;/INIT-PARAM&G
        T <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name >dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app> 
7.2 Writing the spring configuration file Dispatcher-servlet.xml

To add MVC driver, annotation detection, view resolution, and so on. The Dispatcher-servlet.xml code is as follows:

XML code

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:a
       op= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:context= "Http://www.springframework.org/schema/context" 
       Xmlns:mvc= "Http://www.springframework.org/schema/mvc" xmlns:tx= "Http://www.springframework.org/schema/tx" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://www.springframework.org/schema /AOP http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/ Beans Http://www.springframework.org/schema/beans/spring-beans-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SC Hema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd Http://www.springframe WORK.ORG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd Http://www.springframew 
       Ork.org/schema/tx Http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "> <mvc:annotation-driven/> <context:comp Onent-scan base-package= "Com.xujj"/> <bean class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "> <property name=" prefix "value="/web-inf /views/"/> <property name=" suffix "value=". jsp "/> </bean> </beans>

-------------------------------------------------------------------------------------------------above is an negligible part
Maven consolidates tomcat to support hot deployment

1, in Tomcat in the Conf tomcat_users.xml to create management users and passwords, general election Manager-script, in the pom.xml of the Tomcat plug-in with text, or 403 errors may occur

<tomcat-users>
<role rolename= "Manager-script"/>
<user username= "admin" password= "password" roles= "Manager-script"/>
</tomcat-users>

Tomcat role changed:
Note This for Tomcat 7 onwards, the roles required to "use" Manager application were changed from the single manager Rol E to the following four roles. You'll need to assign the "role" (s) required for the functionality you wish to access.
Manager-gui-allows access to the HTML GUI and the status pages
Manager-script-allows access to the text interface and the status pages
Manager-jmx-allows access to the JMX proxy and the status pages
Manager-status-allows access to the status of pages only
Only Manager-gui role can be used.

2, start Tomcat, and then Access http://localhost:8080/manager/html, enter Admin/password, if the Tomcat default interface, which means Tomcat all OK, then you can continue the operation later.

3. Configure the Tomcat plug-in in the project based on the build in the Pom.xml file in the directory

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<url>http://localhost:8080/manager/text</url>

<!--

2, Deploy:eg Http://localhost:8080/manager/deploy?path=/phoenix&war=&update=true
But the deploy URL does not find.
The warning is as follows:
The page tried to access (/manager/deploy) does not exist.
The Manager application has been re-structured for Tomcat 7 onwards and some of URLs have changed. All URLs used to access the Manager application should now-start with one of the following options:
/manager/html for the HTML GUI
/manager/text for the text interface
/manager/jmxproxy for the JMX proxy
/manager/status for the status pages

-->
<username>admin</username>
<password>admin</password>
<path>/baseinfo</path>
</configuration>
</plugin>
</plugins>

1. The following error occurred when performing Tomcat:deploy, due to inconsistency between the user name or password configured in Tomcat-users and Pom.xml

Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy (DEFAULT-CLI) on Project Webs:cannot invoke TOMC At Manager:server returned HTTP response code:401 for url:http://localhost:8080/manager/text/deploy?path=%2fwebs& War=-> [Help 1]

Reboot Tomcat, execute command again

2, must start Tomcat and then execute Tomcat:deploy or Tomcat:redeploy, otherwise the report connection is denied the error message

Cannot invoke Tomcat manager:connection Refused:connect

3, 403 error is due to Tomcat's role settings problem, modify the role name can

Then open Tomcat's WebApps directory and deploy the project to the folder, and the browser opens the page test successfully.


Record the relevant plug-ins and knowledge involved in the configuration:

1, mention uses the Maven-war-plugin plug-in to generate the war, but does not use the plug-in in Tomcat also generated the project's War package,

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>

2, the first project in Pom.xml configured the following nodes, I do not know whether it can be omitted

<repositories>
<repository>
<id>people.apache.snapshots</id>
<url> Http://repository.apache.org/content/groups/snapshots-group/</url>
<releases>
<enabled >false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginrepositories>
< pluginrepository>  
   <id>apache.snapshots</id>  
   <name >apache snapshots</name>  
   <url>  
       http:// repository.apache.org/content/groups/snapshots-group/ 

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.