Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有条件地排除与常春藤的某些依赖关系_Java_Ant_Dependency Management_Ivy - Fatal编程技术网

Java 有条件地排除与常春藤的某些依赖关系

Java 有条件地排除与常春藤的某些依赖关系,java,ant,dependency-management,ivy,Java,Ant,Dependency Management,Ivy,My dependencies.xml包含运行web应用程序所需的许多包 以下是一些值得注意的片段 <configurations> <conf name="test" visibility="public" extends="compile" /> <conf name="compile" visibility="public" extends="runtime" /> <conf name="runtime" visibili

My dependencies.xml包含运行web应用程序所需的许多包

以下是一些值得注意的片段

<configurations>
    <conf name="test" visibility="public" extends="compile" />
    <conf name="compile" visibility="public" extends="runtime" />
    <conf name="runtime" visibility="public" />
    <conf name="provided" visibility="public" />
    <conf name="junit" visibility="public" extends="test" />
</configurations>


<publications>
    <artifact name="${project.name}" type="jar" ext="jar" conf="compile" />
    <artifact name="${project.name}" type="zip" ext="zip" conf="compile"/>
</publications>


<dependencies>


    <dependency org="org.hibernate"                     name="hibernate-core"                   rev="5.1.3.Final"       transitive="false"          conf="runtime->*"/>
    <dependency org="org.hibernate"                     name="hibernate-ehcache"                rev="5.1.3.Final"       transitive="false"          conf="runtime->*"/>
    <dependency org="org.hibernate.common"              name="hibernate-commons-annotations"    rev="5.0.1.Final"       transitive="false"          conf="runtime->*"/>
    <dependency org="org.hibernate.javax.persistence"   name="hibernate-jpa-2.1-api"            rev="1.0.0.Final"       transitive="false"          conf="runtime->*"/>
    <dependency org="org.javassist"                     name="javassist"                        rev="3.21.0-GA"         transitive="false"          conf="runtime->*"/>
    <dependency org="org.jboss.logging"                 name="jboss-logging"                    rev="3.3.0.Final"       transitive="false"          conf="runtime->*"/>
    <dependency org="javax.transaction"                 name="jta"                              rev="1.1"               transitive="false"          conf="runtime->*"/>
    <dependency org="net.sf.ehcache"                    name="ehcache-core"                     rev="2.6.11"            transitive="false"          conf="runtime->*"/>
    <dependency org="antlr"                             name="antlr"                            rev="2.7.7"             transitive="false"          conf="runtime->*"/>
    <dependency org="org.antlr"                         name="antlr4-runtime"                   rev="4.5.2-1"           transitive="false"          conf="runtime->*"/>

</dependencies>

我有javax.transaction中的JTA包,它是应用程序在Tomcat下运行所必需的,是应用程序在WebSphere下运行所禁止的

我需要知道如何根据目标平台制作两个不同的WAR文件。如果是这样的话,我不知道如何使用配置

Ant将为配置
运行时
执行
常春藤检索
,并使用从Artifactory下载的JAR构建WAR归档

我可以在Ivy解决工件后通过删除手动排除thos jar,但是,嘿,我们是很酷的开发人员,我们喜欢以更干净的方式做事情

您建议我如何执行针对Tomcat(包括JTA)的
ivy retrieve
,以及针对Websphere(不包括它)的另一个
build.xml:构建war文件
以下片段构建了两个war文件:

  • ../demo.war
  • ../demo-websphere.war
神奇之处在于tomcat检索任务包括两种配置:

<ivy:retrieve pattern="${lib.dir}/tomcat/[artifact].[ext]" conf="runtime,tomcat_only"/>

<war destfile="${dist.dir}/demo.war" webxml="${resources.dir}/web.xml">
  <fileset dir="${resources.dir}" excludes="web.xml"/>
  <lib dir="${lib.dir}/tomcat"/>
</war>

<ivy:retrieve pattern="${lib.dir}/websphere/[artifact].[ext]" conf="runtime"/>

<war destfile="${dist.dir}/demo-websphere.war" webxml="${resources.dir}/web.xml">
  <fileset dir="${resources.dir}" excludes="web.xml"/>
  <lib dir="${lib.dir}/websphere"/>
</war>
(二) “extends”属性是一个set操作,这意味着编译依赖项将自动包含为运行时配置

图书馆就是一个例子。编译代码时需要slf4j api jar,因为slf4j-log4j12 jar包含对log4j的绑定和依赖项,即运行时(和可变)依赖项

(三) 模块中的“主”配置是特殊的,按照Maven world的惯例,它对应于该模块发布的文件

(四) “分类器”属性是常春藤中的一个示例

<target name="prepare" description="Generate POM">
    <!-- Optional: Intermediate file containing resolved version numbers -->
    <ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${publish.revision}" status="release"/>

    <!-- Generate the Maven POM -->
    <ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/demo.pom"/>
</target>
<target name="publish" depends="init,prepare" description="Upload to Nexus">
    <ivy:publish resolver="nexus-deploy" pubrevision="${publish.revision}" overwrite="true" publishivy="false" >
        <artifacts pattern="${build.dir}/[artifact](-[classifier]).[ext]"/>
    </ivy:publish>
</target>
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
  <info organisation="com.myspotontheweb" module="demo"/>

  <configurations>
    <conf name="master"/>
    <conf name="default" extends="master,runtime"/>
    <conf name="compile"/>
    <conf name="provided"/>
    <conf name="runtime" extends="compile"/>
    <conf name="test"    extends="runtime"/>
    <conf name="tomcat_only" description="A special configuration for special tomcat only dependencies"/>
  </configurations>

  <publications>
    <artifact name="demo" type="war" conf="master"/>
    <artifact name="demo" type="pom" conf="master"/>
    <artifact name="demo" type="war" conf="master" e:classifier="websphere"/>
  </publications>

  <dependencies>
    <!-- Compile dependencies -->
    <dependency org="org.hibernate" name="hibernate-core" rev="5.1.3.Final" conf="compile->default"/>
    <dependency org="org.api" name="slf4j-api" rev="1.7.22" conf="compile->default"/>

    <!-- Runtime dependencies -->
    <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.22" conf="runtime->default"/>

    <!-- Tomcat dependencies -->
    <dependency org="javax.transaction" name="jta" rev="1.1" conf="tomcat_only->master"/>
  </dependencies>

</ivy-module>
config1->default   # Remote artifact plus transitive dependencies
config2->master    # Remote artifact only (Same as setting transitive=false)