Maven-built WebApp basic configuration

Source: Internet
Author: User
Tags log4j

First, the core dependence

The dependency of WebApp is broadly divided into three parts: Basic Spring component dependencies, log and test components, Web Component dependencies, and so on. The approximate:

<dependencies> <!--1.base Spring Dependency---<dependency> <groupid>org.springframew Ork</groupid> <artifactId>spring-core</artifactId> &LT;VERSION&GT;${VERSION.SPRINGFRAMEWORK}&L t;/version> </dependency> <dependency> <groupId>org.springframework</groupId> & Lt;artifactid>spring-beans</artifactid> <version>${version.springframework}</version> </ dependency> <dependency> <groupId>org.springframework</groupId> <artifactid>spring -context</artifactid> <version>${version.springframework}</version> </dependency> <d Ependency> <groupId>org.springframework</groupId> <artifactid>spring-context-support</ar Tifactid> <version>${version.springframework}</version> </dependency> <!--2.base L Ogger and test dependency-<dependency> <groupId>org.apache.logging.log4j</groupId> <artifactid>log4j-cor      e</artifactid> <version>${version.log4j}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${versi      on.slf4j}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${version.slf4j}</version> </ dependency> <dependency> <groupId>junit</groupId> <artifactid>junit</artifactid > <version>${version.junit}</version> <scope>test</scope> </dependency> & Lt;dependency> <groupId>org.springframework</groupId> <artifactid>spring-test</artifacti D> <version>${versioN.springframework}</version> <scope>test</scope> </dependency> <!--3.base Web D Ependency-<dependency> <groupId>org.springframework</groupId> <artifactid>spri ng-web</artifactid> <version>${version.springframework}</version> </dependency> &LT;DEP Endency> <groupId>org.springframework</groupId> <artifactid>spring-webmvc</artifactid&gt      ; <version>${version.springframework}</version> </dependency> <dependency> <groupid&gt ;javax.servlet</groupid> <artifactId>javax.servlet-api</artifactId> &LT;VERSION&GT;${VERSION.J      avax.servlet.api}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> & Lt;version>${version.javax.servlet.jsp.api}</version> <scope>provided</scope> </dependency> <depen dency> <groupId>com.tutianer</groupId> <artifactId>common</artifactId> <versi On>${version.tutianer.common}</version> </dependency> </dependencies>
View Code

Second, the project construction configuration

A common configuration item for project building is to set up JDK versions and resource filtering. As follows:

<build> <pluginManagement> <plugins> <plugin> <groupid>org.apache.ma Ven.plugins</groupid> <artifactId>maven-compiler-plugin</artifactId> <configuration > <source>1.8</source> <target>1.8</target> &LT;/CONFIGURATION&G        T </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifa              Ctid>maven-resources-plugin</artifactid> <configuration> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> & Lt;filtering>true</filtering> </resource> </resources> </configuration> &lt ;/plugin> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactid>je Tty-maven-plugin</artifactid> <version>${version.jetty}</version> <configuration&gt            ; View Code

Where Finalename represents WebApp's packaged name, as the default Web project, set to ROOT can be used directly in Tomcat.

Third, attribute configuration

<profiles> <profile> <id>dev</id> <activation> &LT;ACTIVEB Ydefault>true</activeByDefault> </activation> <properties> <config.logger.level>in Fo</config.logger.level> <config.redis.server>127.0.0.1</config.redis.server> < Config.redis.port>6379</config.redis.port> <config.redis.prefixkey>local_</config.redis.prefi Xkey> <config.db.driverClassName>com.mysql.jdbc.Driver</config.db.driverClassName> &L T;config.db.url>jdbc:mysql://localhost:3306/dbname?characterencoding=utf8&amp;useunicode=true&amp;usessl=false</ Config.db.url><config.db.username>root</config.db.username> <config.db.password>123456</config.db.passwo Rd> <config.domain>http://localhost:8002</config.domain></properties> </profile> <profile> <id>prod</id> <properties&            Gt <config.logger.level>INFO</config.logger.level> <config.redis.server>127.0.0.1</config.red Is.server> <config.redis.port>6382</config.redis.port> <config.redis.prefixKey> Prod_</config.redis.prefixkey> <config.db.driverclassname>com.mysql.jdbc.driver</config.db.drive Rclassname> <config.db.url>jdbc:mysql://localhost:3306/dbname?characterencoding=utf8&amp;useunicode=true&amp;usessl=false</ Config.db.url><config.db.username>username</config.db.username> &LT;CONFIG.DB.PASSWORD&GT;PWD&LT;/CONFIG.DB.PASSW Ord> <config.domain>http://domain</config.domain></properties> </profile> </profiles>
View Code

In general development, a common problem is to switch back and forth in several environments, such as local development, testing, production, and so on, and Maven's property configuration is a good solution. When the Maven-resources-plugin plug-in is used in a project build configuration, the values configured in the properties are automatically replaced in the resource directory specified by Maven-resources-plugin when testing or packaging.

It is important to note that the database configuration is escaped with &amp;, and that the item is configured directly in the XML file and does not need to be escaped.

The default activation is the configuration section where Activebydefault is located, and activating other configurations when packaging or testing requires the parameter p to specify the active configuration item:-P PROD

Iv. Web Version Configuration

Since Maven's archvetype is slightly stale, the created WebApp will be set to version 2.3 and can be modified to 2.5 in the configuration file. The configuration file is a Org.eclipse.wst.common.project.facet.core.xml file in the Web project. Setting directory, which will

<installed facet= "Jst.web" version= "2.3"/>

Modified to:

<installed facet= "Jst.web" version= "2.5"/>

Five, the rest of the configuration

Other configuration information such as spring, Web. XML, etc.

Maven-built WebApp basic configuration

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.