`

Referencing the Maven Classpaths

 
阅读更多

A property is set in the Ant build for each project dependency. Each property name uses the format groupId:artifactId:type[:classifier]. For example, to show the path to a jar dependency with groupId "org.apache" and artifactId "common-util", the following could be used.

<echo message="${org.apache:common-util:jar}"/> 

If the dependency includes a classifier, the classifier is appended to the property name. For example, groupId "org.apache", artifactId "common-util", type "jar", and classifier "jdk14".

<echo message="${org.apache:common-util:jar:jdk14}"/> 

Note: the old format "maven.dependency.groupId.artifactId[.classifier].type.path" has been deprecated and should no longer be used.

You can also use these classpath references:

  • maven.compile.classpath
  • maven.runtime.classpath
  • maven.test.classpath
  • maven.plugin.classpath

For example, to display Maven's classpaths using antrun, we can do this

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-test-app</artifactId>
  <groupId>my-test-group</groupId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
              <target>
                <property name="compile_classpath" refid="maven.compile.classpath"/>
                <property name="runtime_classpath" refid="maven.runtime.classpath"/>
                <property name="test_classpath" refid="maven.test.classpath"/>
                <property name="plugin_classpath" refid="maven.plugin.classpath"/>

                <echo message="compile classpath: ${compile_classpath}"/>
                <echo message="runtime classpath: ${runtime_classpath}"/>
                <echo message="test classpath:    ${test_classpath}"/>
                <echo message="plugin classpath:  ${plugin_classpath}"/>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

or alternatively, we can use an external build.xml.

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-test-app</artifactId>
  <groupId>my-test-group</groupId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
              <target>
                <property name="compile_classpath" refid="maven.compile.classpath"/>
                <property name="runtime_classpath" refid="maven.runtime.classpath"/>
                <property name="test_classpath" refid="maven.test.classpath"/>
                <property name="plugin_classpath" refid="maven.plugin.classpath"/>

                <ant antfile="${basedir}/build.xml">
                  <target name="test"/>
                </ant>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The build.xml:

<?xml version="1.0"?>
<project name="test6">

    <target name="test">

      <echo message="compile classpath: ${compile_classpath}"/>
      <echo message="runtime classpath: ${runtime_classpath}"/>
      <echo message="test classpath:    ${test_classpath}"/>
      <echo message="plugin classpath:  ${plugin_classpath}"/>

    </target>

</project>
分享到:
评论

相关推荐

    Maven权威指南 很精典的学习教程,比ANT更好用

    Maven权威指南 Authors Tim O'Brien (Sonatype, Inc.) , John Casey (Sonatype, Inc.) , Brian Fox (Sonatype, Inc.) , Bruce Snyder () , Jason Van Zyl (Sonatype, Inc.) , Juven Xu () Abstract Maven权威指南...

    Referencing using the Harvard author-date

    Referencing using the Harvard author-date 是科技工作者发表论文必须要掌握的要点,大名鼎鼎不多说了。

    线性参考(Linear Referencing)

    在地理信息系统(GIS)领域中,线性参考(Linear Referencing)技术作为一种专门用于线型特征数据管理和分析的方法,具有其独特的优势和应用。它通过使用已知的线型特征及其上的测量值来确定位置,不再依赖于传统的...

    《Pro Oracle SQL》CHAPTER 9 -- 9.2 Inter-Row Referencing via the Model clause

    9.2章节专注于Inter-Row Referencing,即在不同行之间建立参照关系,以实现数据的迭代计算或处理。 Model子句是Oracle数据库特有的,它提供了一种灵活的数据处理方式,可以用于解决一些常规SQL难以处理的问题,如...

    pentaho-kettle-master.zip

    Submit a pull request, referencing the relevant Jira case Attach a Git patch file to the relevant Jira case Use of the Pentaho checkstyle format (via mvn checkstyle:check and reviewing the report) ...

    线性参考(Linear Referencing and ArcGIS)

    线性参考(Linear Referencing)是一种在地理信息系统(GIS)中表示和管理线性地物,如公路、城市街道、铁路、输电线网络以及供水和排水管道系统等的方法。它侧重于基于线性特征的长度或位置来描述事件或属性,而非...

    geotools包,下载后单独本地上传到maven

    2. **gt-referencing-14.5.jar**:这个模块专注于地理参考,包括坐标系统、投影转换等功能。它实现了OpenGIS规范中的坐标参考系服务,确保地理位置的准确表示。 3. **gt-metadata-14.5.jar**:这个组件处理元数据,...

    Harvard Referencing Guide

    哈佛引用系统(Harvard Referencing System)是一种广泛应用于学术写作中的文献引用格式,它以作者姓名和出版年份作为引文的基本元素,从而方便读者快速定位到参考文献列表中的对应条目。这种引用方式在社会科学领域...

    model_referencing.zip_targetlink

    《模型引用(model_referencing)与TargetLink在工程实践中的应用》 在现代的控制系统设计中,模型引用(model_referencing)和TargetLink是两种强大的工具,它们在提高开发效率和保证系统性能方面起着至关重要的作用。...

    Harvard Referencing

    The Art of Writing. 2nd ed. New York: Wiley. - **期刊文章** - 基本格式:作者姓氏, 名字缩写 (年份). 文章标题. 期刊名称, 卷号(期号), 页码. - 例:Johnson, K. (2019). Understanding Harvard Referencing...

    The Java EE 6 Tutorial Basic Concepts 4th Edition

    Creating a RESTful Root Resource Class 220 Example Applications for JAX-RS 235 Further Information about JAX-RS 240 Part IV: Enterprise Beans 243 Chapter 14: Enterprise Beans 245 What Is an ...

    Android代码-Filepicker Android版

    The library provides an activity that your app can spawn that allows the user to open and save files. Including In Your Project This library is distributed as Android library project so it can be ...

    文献查询及索引information searching and referencing.ppt

    文献查询及索引information searching and referencing

    pro Spring

    Become aware of the seamlessness and power of Spring by referencing the easy-to- understand sample application we provide. Learn how to replace common EJB features with Spring alternatives, including...

    dx修复工具

    Once the users click the button “Check and Repair” on the main form, the programme will finish verification, checking, downloading, repairing and registering automatically, without any further ...

    STD-A0084_GeneralElectricalHardwareRequirementsandGuidelines

    referencing the appropriate section of this document. 1.3 Requirement Wording Conventions Within this document, the following conventions are applied: The word "shall" is to be used in the following...

    NGUI Next-Gen UI 3.9.1

    - NEW: Added UICamera.first referencing the active NGUI event system. - FIX: Alpha should now work as expected with Linear lighting. - FIX: UICamera.isOverUI should now work properly for all types of ...

    matopt.rar_Preallocation_The Profiler_array processing

    本文档介绍了如何使用各种内嵌工具,函数和其他一些小技巧来加强使用matlab的速度和效率,是广大爱好者必读的... * Referencing Operations * Numerical Integration * Signal Processing * Miscellaneous Tricks

    mu Referencing Framework-开源

    muRF 是一种突出显示文档的方法,以提供有关源质量的信息,与斜体强调的方式非常相似。 想想维基百科。 开发是 Firefox 插件和相关的服务器应用程序。

Global site tag (gtag.js) - Google Analytics