Maven中Pom文件打包配置build

摘自:https://my.oschina.net/simpleton/blog/607776

方法一

<build>
    <finalName>###架包名###finalName>
    <sourceDirectory>src/main/javasourceDirectory>
    <resources>
        
        <resource>
            <directory>src/main/resourcesdirectory>
            <targetPath>${project.build.directory}targetPath>
            
            
            <excludes>
                <exclude>*.txtexclude>
            excludes>
            
            <includes>
                <include>*.propertiesinclude>
            includes>
        resource>
    resources>
    <plugins>
        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-compiler-pluginartifactId>
            <configuration>
                <defaultLibBundleDir>libdefaultLibBundleDir>
                <source>1.7source>
                <target>1.7target>
                <encoding>UTF-8encoding>
            configuration>
        plugin>
        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-jar-pluginartifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>trueaddClasspath>
                        <classpathPrefix>lib/classpathPrefix>
                        <mainClass>com.eya.main.HellomainClass>
                    manifest>
                archive>
            configuration>
        plugin>
        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-dependency-pluginartifactId>
            <executions>
                <execution>
                    <id>copyid>
                    <phase>packagephase>
                    <goals>
                        <goal>copy-dependenciesgoal>
                    goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/lib
                        outputDirectory>
                    configuration>
                execution>
            executions>
        plugin>
        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-resources-pluginartifactId>
            <version>2.4version>
            <configuration>
                <encoding>UTF-8encoding>
            configuration>
        plugin>
        
        <plugin>
            <artifactId>maven-source-pluginartifactId>
            <version>2.1version>
            <configuration>
                <attach>trueattach>
                <encoding>UTF-8encoding>
            configuration>
            <executions>
                <execution>
                    <phase>compilephase>
                    <goals>
                        <goal>jargoal>
                    goals>
                execution>
            executions>
        plugin>
    plugins>
build>

<profiles>
        <profile>
            <id>Aid>
            <build>
                <filters>
                    <filter>路径/application-环境名.propertiesfilter>
                filters>
            build>
        profile>
        <profile>
            <id>Bid>
            <build>
                <filters>
                    <filter>路径/application-环境名.propertiesfilter>
                filters>
            build>
        profile>
        <profile>
            <id>devid>
            <build>
                <filters>
                    <filter>路径/application-环境名.propertiesfilter>
                filters>
            build>
        profile>
    profiles>

方法二:

<build>
        <resources>
            <resource>
                <targetPath>${project.build.directory}/classestargetPath>
                <directory>src/main/resourcesdirectory>
                <filtering>truefiltering>
                <includes>
                    <include>**/*.xmlinclude>
                includes>
            resource>
        resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.0version>
                <configuration>
                    <source>1.6source>
                    <target>1.6target>
                    <encoding>UTF-8encoding>
                configuration>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-shade-pluginartifactId>
                <version>2.0version>
                <executions>
                    <execution>
                        <phase>packagephase>
                        <goals>
                            <goal>shadegoal>
                        goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.test.testguava.app.AppmainClass>
                                transformer>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>applicationContext.xmlresource>
                                transformer>
                            transformers>
                            <shadedArtifactAttached>trueshadedArtifactAttached>
                            <shadedClassifierName>executableshadedClassifierName>
                        configuration>
                    execution>
                executions>
            plugin>
        plugins>
    build>
    <profiles>
        <profile>
            <id>Aid>
            <build>
                <filters>
                    <filter>路径/application-环境名.propertiesfilter>
                filters>
            build>
        profile>
        <profile>
            <id>Bid>
            <build>
                <filters>
                    <filter>路径/application-环境名.propertiesfilter>
                filters>
            build>
        profile>
        <profile>
            <id>devid>
            <build>
                <filters>
                    <filter>路径/application-环境名.propertiesfilter>
                filters>
            build>
        profile>
    profiles>

方法三

    <profiles>
        <profile>
            <id>testid>
            <activation>
                <activeByDefault>trueactiveByDefault>
            activation>
            <properties>
                <build.profile.id>testbuild.profile.id>
            properties>
        profile>
        <profile>
            <id>developid>
            <properties>
                <build.profile.id>developbuild.profile.id>
            properties>
        profile>
        <profile>
            <id>formalid>
            <properties>
                <build.profile.id>formalbuild.profile.id>
            properties>
        profile>
    profiles>

    <build>
        <filters>
            <filter>src/app-${build.profile.id}.propertiesfilter>
        filters>
        <sourceDirectory>src/main/javasourceDirectory>
        
        <resources>
            <resource>
                <filtering>truefiltering>
                
                <directory>${project.basedir}/src/main/resourcesdirectory>
            resource>
        resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-shade-pluginartifactId>
                <version>2.4.2version>
                <configuration>
                    <createDependencyReducedPom>truecreateDependencyReducedPom>
                    <filters>
                        <filter>
                            <artifact>*:*artifact>
                            <excludes>
                                <exclude>META-INF/*.SFexclude>
                                <exclude>META-INF/*.DSAexclude>
                                <exclude>META-INF/*.RSAexclude>
                            excludes>
                        filter>
                    filters>
                configuration>
                <executions>
                    <execution>
                        <phase>packagephase>
                        <goals>
                            <goal>shadegoal>
                        goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.***.MainmainClass>
                                transformer>
                            transformers>
                        configuration>
                    execution>
                executions>
            plugin>

        plugins>
    build>

你可能感兴趣的:(问题)