Maven technology sharing (I) Construction of a standard maven Project

Source: Internet
Author: User

Maven technology sharing (I) Construction of a standard maven Project
1, The directory structure is as follows:

Aggregator: Aggregates various maven projects;

SDS_BASEDATA: A web sub-project that will be merged into the SDS_PLATFORM web project.

SDS_PLATFORM: collects various web sub-projects and is to be released to tomcat for running.

2. Introduction to pom files of various projects

Pom file of the aggregator Project

<? Xml version = "1.0" encoding = "UTF-8"?>

<Project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<ModelVersion> 4.0.0 </modelVersion>

<GroupId> com. policysoft. sds </groupId>

<ArtifactId>Aggregator</ArtifactId>

<Version> 1.0.0 </version>

<Packaging>Pom</Packaging>

<Name>AggregatorProject </name>

<DistributionManagement>

<SnapshotRepository>

<Id> user-snapshots </id>

<Name> User Project SNAPSHOTS </name>

<Url> http: // localhost: 8081/nexus/content/repositories/user_snapshot/</url>

</SnapshotRepository>

<Repository>

<Id> user-releases </id>

<Name> User Project Release </name>

<Url> http: // localhost: 8081/nexus/content/repositories/user_release/</url>

</Repository>

</DistributionManagement>

<Modules>

<Module> ../Basedata</Module>

<Module> ../platform </module>

</Modules>

</Project>

Pom configuration of the merged project SDS_BASEDATA

<? Xml version = "1.0"?>

<Project xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns = "http://maven.apache.org/POM/4.0.0"

Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance">

<ModelVersion> 4.0.0 </modelVersion>

<Parent>

<GroupId> com. policysoft. sds </groupId>

<ArtifactId>Aggregator</ArtifactId>

<Version> 1.0.0 </version>

<RelativePath> ../Aggregator</RelativePath>

</Parent>

<GroupId> com. policysoft. sds </groupId>

<ArtifactId>Basedata</ArtifactId>

<Version> 1.0.0 </version>

<Packaging> war </packaging>

<Name>Sds-Basedata</Name>

<Build>

<FinalName>Sds-Basedata</FinalName>

<Plugins>

<Plugin>

<GroupId> org. apache. maven. plugins </groupId>

<ArtifactId>Maven-War-Plugin</ArtifactId>

<Version> version 2.1-beta-1 </version>

<Configuration>

<! -- Ignore web. xml mandatory requirements -->

<FailOnMissingWebXml> false </failOnMissingWebXml>

<! -- Specify the source code and page path -->

<WebappDirectory>

Target/$ {artifactId}

</WebappDirectory>

<WarSourceDirectory>

WebRoot

</WarSourceDirectory>

<WebResources>

<Resource>

<Directory> WebRoot \ WEB-INF </directory>

<TargetPath> WEB-INF </targetPath>

</Resource>

</WebResources>

</Configuration>

</Plugin>

<Plugin>

<GroupId> org. codehaus. cargo </groupId>

<ArtifactId> cargo-maven2-Plugin</ArtifactId>

<Version> 1.3.2 </version>

<Configuration>

<! -- If the project is not automatically released by cargo, the project content is merged into the main web project platform -->

<Skip> true </skip>

</Configuration>

</Plugin>

</Plugins>

</Build>

</Project>

Pom configuration of SDS_PLATFORM

<? Xml version = "1.0" encoding = "UTF-8"?>

<Project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<Parent>

<GroupId> com. policysoft. sds </groupId>

<ArtifactId>Aggregator</ArtifactId>

<Version> 1.0.0 </version>

<RelativePath> ../Aggregator</RelativePath>

</Parent>

<ModelVersion> 4.0.0 </modelVersion>

<GroupId> com. policysoft. sds </groupId>

<ArtifactId> platform </artifactId>

<Version> 1.0.0 </version>

<Packaging> war </packaging>

<Name> platform project </name>

<Build>

<Plugins>

<Plugin>

<GroupId> org. apache. maven. plugins </groupId>

<ArtifactId>Maven-War-Plugin</ArtifactId>

<Version> version 2.1-beta-1 </version>

<Configuration>

<! -- Specify the source code and page path -->

<WebappDirectory>

Target/$ {artifactId}

</WebappDirectory>

<WarSourceDirectory>

WebRoot

</WarSourceDirectory>

<WebResources>

<Resource>

<Directory> WebRoot \ WEB-INF </directory>

<TargetPath> WEB-INF </targetPath>

<Filtering> true </filtering>

<Shortdes>

<Include> web. xml </include>

</Shortdes>

</Resource>

</WebResources>

<! -- Specify the project to be merged -->

<Overlays>

<Overlay>

<GroupId> com. policysoft. sds </groupId>

<ArtifactId> basedata </artifactId>

</Overlay>

</Overlays>

</Configuration>

</Plugin>

<Plugin>

<GroupId> org. codehaus. cargo </groupId>

<ArtifactId> cargo-maven2-Plugin</ArtifactId>

<Version> 1.3.2 </version>

<! -- Set remote tomcat parameters -->

<Configuration>

<Wait> true </wait>

<! -- Container configuration -->

<Container>

<ContainerId> tomcat6x </containerId>

<Type> remote </type>

<Timeout> 600000 </timeout>

</Container>

<! -- Configuration to use with the container -->

<Configuration>

<Type> runtime </type>

<Properties>

<Cargo. tomcat. manager. url> http: // 127.0.0.1: 8080/manager/text </cargo. tomcat. manager. url>

<Cargo. hostname> 127.0.0.1 </cargo. hostname>

<Cargo. servlet. port> 8080 </cargo. servlet. port>

<Cargo. remote. username> tomcat </cargo. remote. username>

<Cargo. remote. password> tomcat </cargo. remote. password>

</Properties>

</Configuration>

<! --DeployerConfiguration -->

<Deployer>

<Type> remote </type>

<! --DeployablesConfiguration -->

<Deployables>

<Deployable>

<GroupId> com. policysoft. sds </groupId>

<ArtifactId> platform </artifactId>

<Type> war </type>

<Properties>

<Context>/platform </context>

</Properties>

</Deployable>

</Deployables>

</Deployer>

</Configuration>

<! -- Bind the project lifecycle in maven -->

<Executions>

<Execution>

<Id>Redeploy</Id>

<Phase> deploy </phase>

<Goals>

<Goal>Redeploy</Goal>

</Goals>

</Execution>

</Executions>

</Plugin>

</Plugins>

</Build>

<! -- When merging a project, you must specify the project to be merged in dependencies -->

<Dependencies>

<Dependency>

<GroupId> com. policysoft. sds </groupId>

<ArtifactId>Basedata</ArtifactId>

<Version> 1.0.0 </version>

<Type> war </type>

</Dependency>

</Dependencies>

</Project>


3. Configure setting. xml in maven

First, the cargo plug-in is not official, so you need to configure it in settings. xml.

<PluginGroups>

<PluginGroup> org. codehaus. cargo </pluginGroup>

</PluginGroups>

4. Configure tomcat

Add an administrator role to tomcat

<? Xml version = '1. 0' encoding = 'utf-8'?>

<Tomcat-users>

<Role rolename = "manager"/>

<User username = "tomcat" password = "tomcat" roles = "manager"/>

</Tomcat-users>


5. Run maven

Mvn clean deploy


Problem:

1) when cargo-core-api-container and cargo-core-api-module of cargo are unstable in the network and cannot connect to the maven server, you need to download and install it separately to the maven nexus resource library.

2) the mvn clean cargo: redploy command will deploy the project to tomcat, but after the pom file is executed, the project will be removed from tomcat.



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.