【整理】将javaWeb工程转成Maven工程

之前碰到过很多javaWeb工程,直接使用lib文件夹管理jar包,缺点多多,jar包版本混乱,不堪其扰,故创建pom、整理成maven管理。

而且这种工程打包基本都是使用eclipse等开发工具打包,不方便使用自动构建工具,使用maven管理可以使用它的打包工具。

  1. 创建pom文件,将配置信息和依赖jar包信息写入其中
    jar包相关信息可以去该网址去查找。
<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.0modelVersion>
    <groupId>com.chongtonggroupId>
    <artifactId>demoartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>demoname>
    <description>demodescription>
    <properties>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <jdk.version>1.8jdk.version>
        <spring.version>3.0.5.RELEASEspring.version>
    properties>
    <dependencies>
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-contextartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-context-supportartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-coreartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-beansartifactId>
            <version>${spring.version}version>
        dependency>
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-webartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-servletartifactId>
            <version>${spring.version}version>
        dependency>
    dependencies>
    <build>
        <finalName>demofinalName>
        <resources>
            <resource>
                <directory>src/main/resourcesdirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
        resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.6.2version>
                <configuration>
                    <source>${jdk.version}source>
                    <target>${jdk.version}target>
                    <encoding>utf8encoding>
                configuration>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-assembly-pluginartifactId>
                <version>3.1.0version>
                
                <configuration>
                    
                    <descriptors>
                        <descriptor>src/main/assembly/package.xmldescriptor>
                    descriptors>
                    
                    <appendAssemblyId>falseappendAssemblyId>
                configuration>
                <executions>
                    <execution>
                        <id>make-assemblyid>
                        <phase>packagephase>
                        <goals>
                            <goal>singlegoal>
                        goals>
                    execution>
                executions>
            plugin>
            <plugin>
                <artifactId>maven-war-pluginartifactId>
                <version>2.6version>
                <configuration>
                    <warSourceDirectory>${basedir}/src/main/webapp
                    warSourceDirectory>
                    <webXml>${basedir}/src/main/webapp/WEB-INF/web.xmlwebXml>
                configuration>
            plugin>
            <plugin>
                <groupId>org.codehaus.mojogroupId>
                <artifactId>findbugs-maven-pluginartifactId>
                <version>2.3version>
                <configuration>
                    <findbugsXmlOutput>truefindbugsXmlOutput>
                    <xmlOutput>truexmlOutput>
                configuration>
            plugin>
        plugins>
    build>
    <packaging>warpackaging>
project>
  1. 创建打包文件package.xml,将打包策略写入其中
 <assembly>
    <id>${project.artifactId}-assembly-${project.version}id>
    
    
    
    <includeBaseDirectory>falseincludeBaseDirectory>
    
    <formats>
        <format>warformat>
    formats>
    <fileSets>
        
        <fileSet>
            <directory>${project.build.outputDirectory}directory>
            <outputDirectory>WEB-INF/classesoutputDirectory>
        fileSet>
        
        <fileSet>
            <directory>${project.basedir}/src/main/webappdirectory>
            <outputDirectory>/outputDirectory>
        fileSet>
    fileSets>
    
    <dependencySets>
        <dependencySet>
            <outputDirectory>WEB-INF/liboutputDirectory>
            <excludes>
                <exclude>${project.groupId}:${project.artifactId}:warexclude>
            excludes>
        dependencySet>
    dependencySets>
assembly> 

你可能感兴趣的:(编程)