maven配置初步之plugs包管理(一)

1、引用本地包

<dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_core</artifactId>
            <version>2.10</version>
            <scope>system</scope>
             <systemPath>E:\Official Projects\Jmeter\apache-jmeter-2.10\lib\ext\ApacheJMeter_core.jar</systemPath>
        </dependency>

</scope>可以使用以下值:

* compile,缺省值,适用于所有阶段,会随着项目一起发布。 
    * provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。 
    * runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。 
    * test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。 
    * system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。

2、jar打包工具,maven-shade-plugin,将依赖包一起打包(它能够将所有jar里的spring.schemas文件进行合并,在最终生成的单一jar包里)

<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.2</version>
                   <executions>
                       <execution>
                           <phase>package</phase>
                           <goals>
                               <goal>shade</goal>
                           </goals>
                           <configuration>
                               <transformers>
                                   <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                       <resource>META-INF/spring.handlers</resource>  
                                   </transformer>
                                   <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                       <resource>META-INF/spring.schemas</resource>  
                                   </transformer>
                               </transformers>
                           </configuration>
                       </execution>
                   </executions>
          </plugin>


3、将配置文件打在jar包之外

<build>

  <plugins>

  <plugin>

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

    <artifactId>maven-jar-plugin</artifactId>  

    <configuration>  

        <archive>  

            <manifest>  

                <addClasspath>true</addClasspath><!-- 加载class -->  

                <classpathPrefix>lib/</classpathPrefix><!-- 加载的class目录的前缀(依赖的jar目录) -->  

                <mainClass>com.bj.ihanysoft.MavenDemo.App</mainClass><!-- 入口类名 -->  

            </manifest>  

        </archive>  

     </configuration>  

  </plugin>

  <plugin>  

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

    <artifactId>maven-dependency-plugin</artifactId>  

    <executions>  

        <execution>  

            <id>copy-dependencies</id>  

            <phase>package</phase>  

            <goals>  

                <goal>copy-dependencies</goal>  

            </goals> 

            <configuration>  

                <outputDirectory>${project.build.directory}/lib</outputDirectory>  

                <overWriteReleases>false</overWriteReleases>  

                <overWriteSnapshots>false</overWriteSnapshots>  

                <overWriteIfNewer>true</overWriteIfNewer>  

            </configuration>  

        </execution>  

    </executions>  

</plugin>  

   <!-- 以utf-8编码拷贝配置文件,拷贝过程中是可以做变量替换的,也就是说你的配置文件可以是个模板,里面的${}所包含的内容是可以拷贝过程中替换的 -->  

<plugin>  

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

    <artifactId>maven-resources-plugin</artifactId>  

    <version>2.4</version>  

    <executions>  

        <execution>  

            <id>copy-resources</id>  

            <phase>package</phase>  

            <goals>  

                <goal>copy-resources</goal>  

            </goals>  

            <configuration>  

                <encoding>UTF-8</encoding>  

                <outputDirectory>${project.build.directory}</outputDirectory><!-- 把配置文件拷到和jar包同一个路径下 -->  

                <resources>  

                    <resource>  

                        <directory>src/main/resource/</directory>  

                        <includes>  

                            <include>s.xml</include>  

                        </includes>  

                        <filtering>true</filtering>  

                    </resource>  

                </resources>  

            </configuration>  

        </execution>  

    </executions>  

</plugin>  

<!-- 打jar包时需要把配置文件给排除在外 -->  

<plugin>  

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

    <artifactId>maven-jar-plugin</artifactId>  

    <executions>  

        <execution>  

            <phase>package</phase>  

            <goals>  

                <goal>jar</goal>  

            </goals>  

            <configuration>  

                <classifier>lib</classifier>  

                <excludes>  

                    <exclude>s.xml</exclude>  

                </excludes>  

            </configuration>  

        </execution>  

    </executions>  

</plugin> 

  </plugins>

  

  <pluginManagement>

<plugins>

    <plugin>

        <groupId>org.eclipse.m2e</groupId>

        <artifactId>lifecycle-mapping</artifactId>

        <version>1.0.0</version>

        <configuration>




转载于:https://my.oschina.net/mutianya/blog/189295

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值