简体   繁体   English

常春藤的conf属性用法错误

[英]Wrong usage of conf attribute of ivy

I think I donot understand well the conf feature of ivy even if I have read the tutorial. 我认为即使我已经阅读了本教程,也不太了解ivy的conf功能。 Think about I have two dependency; 考虑一下我有两个依赖关系;

  • guava.jar 番石榴
  • foeu.jar foeu.jar

I need foeu.jar in compile time only but I need guava.jar not only in compile time but also in runtime. foeu.jar在编译时需要foeu.jar ,但不仅在编译时而且在运行时都需要guava.jar To implement these needs, I have wrote, in ivy.xml; 为了满足这些需求,我在ivy.xml中写道;

<configurations defaultconfmapping="runtime->compile">
    <conf   name="default" 
            visibility="public" />

    <conf   name="compile"      
            visibility="private"/>

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

and, dependency as; 并且,依赖为;

<dependencies>          
    <dependency org="Google Guava"  name="guava-17.0"   rev="17.0"  
                conf="runtime->default"/>
    <dependency org="Foeu"  name="foeu" rev="5.5.1" 
                conf="compile->default"/>
</dependencies>

Really, something wrong with conf understanding of mine. 确实,我对conf理解有些问题。 What is the problem and what should I do? 有什么问题,我该怎么办?

UPDATE: 更新:

In build.xml, I am using it like; 在build.xml中,我像这样使用它;

ivy-initialization; 常春藤初始化

<target name="init-ivy" description="Initialize ivy requirements">
    <property   name="ivy.dep.file"     value="${script.directory}/ivy/ivy.xml" />

    <ivy:configure  file="${script.directory}/ivy/ivyconf.xml"/>

    <ivy:resolve/>
    <ivy:cachepath  pathid="ivy.compile.path"    conf="compile" />
    <ivy:cachepath  pathid="ivy.runtime.path" conf="runtime" />
</target>

compile; 编译

<target name="compile"  depends="init-ivy"  description="Compiling Java source codes with external libraries">
    <javac  compiler="javac1.7"
            destdir="${class.directory}"
            source="1.7"
            target="1.7"
            failonerror="true"
            includeantruntime="false">

            <src    path="${source.directory}" />
            <classpath  refid="ivy.compile.path" />

    </javac>
</target>

jar

<target name="create-jar"   depends="compile"   description="Creating jar files">
    <jar    destfile="${build.directory}/jar/${ant.project.name}.jar"
        basedir="${class.directory}">

        <manifest>
            <attribute name="Main-Class" value="dataScience.management.Management"/>    
        </manifest>
    </jar>
</target>

run

<target name="runtime"  depends="create-jar"    description="Running Java based application">
        <java   jar="${jar.directory}/${ant.project.name}.jar"
                fork="yes"  
                maxmemory="400m">
                <jvmarg value="-ea"/>
                <classpath  refid="ivy.runtime.path" />
        </java>
</target>

Configurations are a tricky concept to understand. 配置是一个难以理解的概念。 My recommendation is to create one for each functional group of dependencies in your build. 我的建议是为构建中的每个功能依赖项组创建一个。

The bit you're looking for is the "extends" attribute. 您要找的位是“扩展”属性。 It enables membership inheritance. 它启用成员资格继承。 For example: 例如:

<configurations>
    <conf name="compile" description="Libraries needed for compilation" />
    <conf name="runtime" extends="compile" description="Libraries needed at runtime"/>
</configurations>

In this way all compile dependencies are automatically part of the runtime configuration. 这样,所有编译依赖项都自动成为运行时配置的一部分。

For more detailed example take a look at the following answer: 有关更详细的示例,请查看以下答案:

Update 更新资料

This is not an ivy issue. 这不是常春藤的问题。 Executable jars require main class and classpath to be present in the manifest file. 可执行jar需要清单文件中包含主类类路径。

Build your jar file as follows: 如下构建您的jar文件:

  <target name="build" depends="compile">
    <ivy:retrieve pattern="${dist.dir}/lib/[artifact].[ext]" conf="runtime"/>

    <manifestclasspath property="jar.classpath" jarfile="${dist.jar}">
      <classpath>
        <fileset dir="${dist.dir}/lib" includes="*.jar"/>
      </classpath>
    </manifestclasspath>

    <jar destfile="${dist.jar}" basedir="${build.dir}/classes">
      <manifest>
        <attribute name="Main-Class" value="${dist.main.class}"/>
        <attribute name="Class-Path" value="${jar.classpath}"/>
      </manifest>
    </jar>
  </target>

The ivy retrieve task populates a local dir with the runtime dependencies. 常春藤检索任务使用运行时相关性填充本地目录。 The manifestclasspath task creates a list of relative links to these files and finally the "Class-Path" entry is added to the manifest file. manifestclasspath任务创建到这些文件的相对链接的列表,最后将“ Class-Path”条目添加到清单文件中。 You will then be able to run the jar as follows: 然后,您将能够如下运行jar:

<java jar="${dist.jar}" fork="yes" maxmemory="400m">
        <jvmarg value="-ea"/>
</java>

In conclusion there is basically two ways to run a jar. 总之,运行jar基本上有两种方法。 Specify the classpath and mainclass or create jar with the main class and classpath in the manifest. 指定classpath和mainclass或在清单中创建带有main class和classpath的jar。

Hope this solves your issue. 希望这能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM