简体   繁体   English

Ant copy classpath jar到目录

[英]Ant copy classpath jars to a directory

I'm sure this has either been asked before or is pretty straightforward. 我确信这要么是之前被要求的,要么是非常简单的。 But for whatever reason, I cannot seem to make it work. 但无论出于何种原因,我似乎无法使其发挥作用。 I want to use ant to copy the ${build.classpath} (which contains a colon separated list of jars) to the ${output.dir}/myapp/WEB-INF/lib . 我想使用ant将${build.classpath} (包含以冒号分隔的jar列表) ${output.dir}/myapp/WEB-INF/lib${output.dir}/myapp/WEB-INF/lib

I have this right now and it doesn't seem to work: 我现在有这个,它似乎不起作用:

<copy toDir="${output.dir}/myapp/WEB-INF/lib">
  <fileset file="${build.classpath}" />
</copy>

It treats the whole classpath as one file. 它将整个类路径视为一个文件。 How do I get this to work? 我如何让它工作?

The Ant Manual on the copy task contains the answer for your problem. 复制任务上的Ant手册包含您的问题的答案。 One of the example snippets it provides: 它提供的示例代码段之一:

Collect all items from the current CLASSPATH setting into a destination directory, flattening the directory structure. 将当前CLASSPATH设置中的所有项目收集到目标目录中,展平目录结构。

<copy todir="dest" flatten="true">
  <path>
    <pathelement path="${java.class.path}"/>
  </path>
</copy>

I think somethink like this should work: 我认为这样的想法应该有效:

<copy todir="${output.dir}/myapp/WEB-INF/lib" verbose="yes" flatten="yes" failonerror="no">    
   <fileset dir="${build.classpath}">    
      <include name="*.jar" />    
   </fileset>    
</copy>

or with wildcard in include: <include name="**/*.jar" /> 或者使用包含的通配符: <include name="**/*.jar" />

I think you should put all your colon separated jar files to one root folder. 我认为你应该将所有冒号分隔的jar文件放到一个根文件夹中。 If it is not possible then create a separate task that put those jar files into one folder(may be temporary). 如果不可能,则创建一个单独的任务,将这些jar文件放入一个文件夹(可能是临时的)。 And assign ${build.classpath} to that folder. 并将${build.classpath}分配给该文件夹。 Use <fileset dir="${build.classpath}"/> in your copy clause. 在copy子句中使用<fileset dir="${build.classpath}"/>

I hope, it should help. 我希望,它应该有所帮助。

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

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