java Ant 将类路径 jars 复制到目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4394641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:10:31  来源:igfitidea点击:

Ant copy classpath jars to a directory

javaantcopyclasspath

提问by Mohamed Nuur

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.

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?

它将整个类路径视为一个文件。我如何让这个工作?

回答by user268396

The Ant Manual on the copy task contains the answer for your problem. One of the example snippets it provides:

复制任务的 Ant 手册包含您的问题的答案。它提供的示例片段之一:

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>

回答by Krzysztof Miksa

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

回答by nIKUNJ

I think you should put all your colon separated jar files to one root folder. If it is not possible then create a separate task that put those jar files into one folder(may be temporary). And assign ${build.classpath}to that folder. Use <fileset dir="${build.classpath}"/>in your copy clause.

我认为您应该将所有以冒号分隔的 jar 文件放在一个根文件夹中。如果不可能,则创建一个单独的任务,将这些 jar 文件放入一个文件夹(可能是临时的)。并分配 ${build.classpath}到该文件夹​​。使用<fileset dir="${build.classpath}"/>您的副本子句。

I hope, it should help.

我希望,它应该有所帮助。