java - 如何使用 ant4eclipse 复制 eclipse 项目的所有引用的 jar?

标签 java ant build-process

我尝试过这样的(link):

<taskdef resource="net/sf/antcontrib/antlib.xml" />
<taskdef resource="net/sf/ant4eclipse/antlib.xml" />

<target name="copy_jars">
  <getEclipseClasspath workspace="${basedir}/.."
                       projectname="MyProject"
                       property="classpath"
                       relative="false"
                       runtime="true"
                       pathseparator="#" />

  <!-- iterate over all classpath entries -->
  <foreach list="${classpath}" delimiter="#"
    target="copy_jar_file" param="classpath.entry" />
</target>

<target name="copy_jar_file">
  <!-- check if current is a .jar-file ... -->
  <if>
    <isfileselected file="${classpath.entry}">
      <filename name="**/*.jar" />
    </isfileselected>
    <then>
      <!-- copy the jar file to a destination directory -->
      <copy file="${classpath.entry}" tofile="${dest.dir}"/>
    </then>
  </if>
</target>

但我得到了异常(exception):

[getEclipseClasspath] net.sf.ant4eclipse.model.FileParserException: Could not parse plugin project 'E:\...\MyProject' since it contains neither a Bundle-Manifest nor a plugin.xml!
[getEclipseClasspath]  at net.sf.ant4eclipse.model.pdesupport.plugin.PluginDescriptorParser.parseEclipseProject(Unknown Source)
[getEclipseClasspath]  at net.sf.ant4eclipse.model.pdesupport.plugin.PluginProjectRoleIdentifier.applyRole(Unknown Source)
[getEclipseClasspath]  at net.sf.ant4eclipse.model.roles.RoleIdentifierRegistry.applyRoles(Unknown Source)
[getEclipseClasspath]  at net.sf.ant4eclipse.tools.ProjectFactory.readProjectFromWorkspace(Unknown Source)
[getEclipseClasspath]  at net.sf.ant4eclipse.tools.resolver.AbstractClasspathResolver.resolveEclipseClasspathEntry(Unknown Source)
[getEclipseClasspath]  at net.sf.ant4eclipse.tools.resolver.AbstractClasspathResolver.resolveProjectClasspath(Unknown Source)
[getEclipseClasspath]  at net.sf.ant4eclipse.tools.resolver.ProjectClasspathResolver.resolveProjectClasspath(Unknown Source)
[getEclipseClasspath]  at net.sf.ant4eclipse.ant.task.project.GetEclipseClassPathTask.resolvePath(Unknown Source)
[getEclipseClasspath]  at net.sf.ant4eclipse.ant.task.project.AbstractGetProjectPathTask.execute(Unknown Source)
[getEclipseClasspath]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[getEclipseClasspath]  at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[getEclipseClasspath]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[getEclipseClasspath]  at java.lang.reflect.Method.invoke(Method.java:597)
[getEclipseClasspath]  at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[getEclipseClasspath]  at org.apache.tools.ant.Task.perform(Task.java:348)
[getEclipseClasspath]  at org.apache.tools.ant.Target.execute(Target.java:357)
[getEclipseClasspath]  at org.apache.tools.ant.Target.performTasks(Target.java:385)
[getEclipseClasspath]  at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[getEclipseClasspath]  at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[getEclipseClasspath]  at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[getEclipseClasspath]  at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[getEclipseClasspath]  at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[getEclipseClasspath]  at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[getEclipseClasspath]  at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
E:\...\build.xml:132: Exception whilst resolving the classpath of project MyProject! Reason: Could not parse plugin project 'E:\...\MyProject' since it contains neither a Bundle-Manifest nor a plugin.xml!

我不想只复制 jar,而不是引用的项目。 有没有办法参数化任务 getEclipseClasspath 以便它只获取 jar,而不获取项目?

最佳答案

验证: 1.projectname 的 getEclipseClasspath 属性实际上是“MyProject” 2.“MyProject”实际上是一个java项目,并且在构建路径中定义了条目 3. 您已将 Ant4Eclipse 和 AntContrib 的 jar 添加到 Ant-Runtime 类路径中: 菜单:Window->Preferences->Ant->Runtime->Classpath(选项卡)->Ant Home Entries->“Add jars”(按钮)

如果仅从您的 ant 脚本中引用 Ant4Eclipse 和 AntContrib,则您引用的示例代码将不起作用 - 必须将这些 jar 添加到 Eclipse 配置中的 Ant 运行时类路径中。

关于java - 如何使用 ant4eclipse 复制 eclipse 项目的所有引用的 jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1606426/

相关文章:

java - 如何杀死从 java 中产生的 Ant 程序

build-process - 配置设置的最佳实践

java - 如何在只有 2 个 Hazelcast 集群节点的 Hazelcast CP 子系统上使用 AtomicLong?

Java .contains 方法

java - 使用 ant 根据 jar 属性编辑文件

c# - 在同一解决方案中的 vdproj 预构建事件中更改 csproj 程序集信息中的产品名称

c# - 确定已发布 DLL 中的调试/ Release模式?没有#DEBUG

java - Android数据库插入语句中用双引号替换单引号

java - 我将如何优化此外观以获得唯一的数字算法功能

java - Junit和Ant集成的另一个简单问题