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

一、引用本地包web

<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>spring

</scope>能够使用如下值:apache

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

二、jar打包工具,maven-shade-plugin,将依赖包一块儿打包(它可以将全部jar里的spring.schemas文件进行合并,在最终生成的单一jar包里)eclipse

<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>
maven


三、将配置文件打在jar包以外ide

<build>工具

  <plugins>测试

  <plugin>ui

  <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>

相关文章
相关标签/搜索