题
我在Eclipse内部运行蚂蚁脚本是其中的一部分:
<p2.composite.repository failOnExists="true">
<repository location="file:/${basedir}/compRepo" name="Repository description goes here" />
<add>
<repository location="http://url/Eclipse/repo/Galileo-3.5.1/" />
<repository location="http://another-url/Java/repo/4.0/" />
<repository location="${diag.location}" />
</add>
</p2.composite.repository>
但我希望 Hudson CI 服务器能够运行它,但是,无论我放入 ANT_HOME/lib 中的所有 jars,我都无法让这个任务在简单的命令行 ant 中运行...我遇到了这个错误:
C:\workspaces\workspace\project\junit.script\createCompRepo.xml:10: Problem: failed to create task or type p2.composite.repository
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
p2 ant 任务在哪里定义?有没有办法在 Eclipse 之外运行它们?非常感谢您的帮助!安东尼
解决方案
通过阅读 这个线程 和 P2 出版商文档, ,它应该在 org.eclipse.equinox.launcher_*.jar
P2 任务的示例(这里不是 ant 任务),仅用于 -jar
争论:
java -jar <targetProductFolder>/plugins/org.eclipse.equinox.launcher_*.jar
-application org.eclipse.equinox.p2.publisher.UpdateSitePublisher
-metadataRepository file:/<some location>/repository
-artifactRepository file:/<some location>/repository
-source /<location with a site.xml>
-configs gtk.linux.x86
-compress
-publishArtifacts
这 P2 Ant 任务描述如下, ,并且在 Eclipse 帮助.
OP 安东尼43 在评论中添加:
我只想在 eclipse 之外运行带有 p2 taskdefs 的 ant 目标。
我发现我应该使用antRunner
, ,使用这样的命令行:
./eclipse -vm /opt/sun-java2-6.0/bin/java -nosplash \
-data ${java.io.tmpdir}/workspace -consolelog \
-application org.eclipse.ant.core.antRunner \
-f /path/to/scripts/partialMirrorFromRepo.xml
但 安德鲁·尼弗 (PDE/Build、p2 和 Equinox 框架上的 Eclipse 提交者)补充道:
这 p2 任务需要在 osgi 环境中运行,并且无法在正常的 ant 运行中运行.
这就是为什么你需要使用org.eclipse.ant.core.antRunner
应用。
从“java -jar launcher.jar”开始只是调用 eclipse 可执行文件的另一种方法。
马丁·雅库比克 提到:
我希望看到一个可以剪切和粘贴并将所有内容组合在一起的命令。
我用的是:
java -jar <eclipse-install-directory>\eclipse\plugins\org.eclipse.equinox.launcher_*.jar -application org.eclipse.ant.core.antRunner.
请注意,我无法弄清楚什么
<targetProductFolder>
是,所以我用了<eclipse-install...>
反而。
其他提示
我创建为确切的目的
小蚂蚁宏<path id="equinox.launcher.path">
<fileset dir="${eclipse.home}/plugins">
<include name="org.eclipse.equinox.launcher_*.jar" />
</fileset>
</path>
<macrodef name="antRunner">
<!-- Ant script location -->
<attribute name="antFile" />
<!-- the arguments for the script that is executed -->
<attribute name="args" default=""/>
<sequential>
<java
classname="org.eclipse.equinox.launcher.Main"
fork="true"
failonerror="true">
<arg line="-application org.eclipse.ant.core.antRunner" />
<arg line="-f @{antFile}" />
<arg line="@{args}"/>
<classpath refid="equinox.launcher.path" />
</java>
</sequential>
</macrodef>
所有P2任务所需要的Eclipse运行时(如明确说明在Eclipse帮助上面提到的),所以你一定要使用Eclipse。
要避开它会分析Eclipse代码的唯一方法,提取所需要的,并用它创建自己的构建系统。
只是为了完成示例 贾里克·普日戈兹基 这是我的解决方案,使用他的蚂蚁文件。我不太熟悉使用ant,所以可能有优化的潜力。这种方法在没有 GUI 的服务器上无头使用,但我必须安装 eclipse。使用 apt-get 安装不起作用,因此最好手动安装(下载并解压)。
- 第一个 antfile 组装名称、版本等......
- 从第一个 antfile 调用第二个 antfile 并创建复合存储库。
第一个蚂蚁文件:
<project name="project">
<!-- ....do some other stuff...-->
<target name="p2.composite.add">
<!--Call macro for child repo-->
<antRunner
name="${site.composite.name}"
location="${composite.repository.directory}"
child="${child.repository}"
/>
<!--Call macro for main repo-->
<antRunner
name="${main.site.composite.name}"
location="${main.composite.repository.directory}"
child="${majorMinorVersion}"
/>
</target>
<!--Eclipse installation path-->
<path id="equinox.launcher.path">
<fileset dir="/usr/share/eclipse/plugins">
<include name="org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar" />
</fileset>
</path>
<macrodef name="antRunner">
<attribute name="name"/>
<attribute name="location"/>
<attribute name="child"/>
<sequential>
<java
classname="org.eclipse.equinox.launcher.Main"
fork="true"
failonerror="true">
<arg line="-application org.eclipse.ant.core.antRunner" />
<arg line="-f addCompositeInternal.ant run" />
<arg line="-Dcomposite.name=@{name}"/>
<arg line="-Dcomposite.location=@{location}"/>
<arg line="-Dcomposite.child=@{child}"/>
<classpath refid="equinox.launcher.path" />
</java>
</sequential>
</macrodef>
</project>
第二个 Ant 文件,名为 addCompositeInternal.ant
<project name="composite">
<target name="run">
<add.composite.repository.internal
composite.repository.location="${composite.location}"
composite.repository.name="${composite.name}"
composite.repository.child="${composite.child}"
/>
</target>
<!-- = = = = = = = = = = = = = = = = =
macrodef: add.composite.repository.internal
= = = = = = = = = = = = = = = = = -->
<macrodef name="add.composite.repository.internal">
<attribute name="composite.repository.location" />
<attribute name="composite.repository.name" />
<attribute name="composite.repository.child" />
<sequential>
<echo message=" " />
<echo message="Composite repository : @{composite.repository.location}" />
<echo message="Composite name : @{composite.repository.name}" />
<echo message="Adding child repository : @{composite.repository.child}" />
<p2.composite.repository>
<repository compressed="false" location="@{composite.repository.location}" name="@{composite.repository.name}" />
<add>
<repository location="@{composite.repository.child}" />
</add>
</p2.composite.repository>
<echo file="@{composite.repository.location}/p2.index">version=1
metadata.repository.factory.order=compositeContent.xml,\!
artifact.repository.factory.order=compositeArtifacts.xml,\!
</echo>
</sequential>
</macrodef>
</project>