【问题标题】:Running P2 Ant tasks outside Eclipse在 Eclipse 之外运行 P2 Ant 任务
【发布时间】:2011-01-20 14:35:12
【问题描述】:

我的 ant 脚本在 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 中的所有 jar 包,我都无法让这个任务在简单的命令行 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 之外运行它们? 非常感谢您的帮助! 安东尼

【问题讨论】:

  • 我已更新我的答案以反映您的发现。注意:Andrew Niefer(PDE/Build、p2 和 Equinox 框架上的 Eclipse 提交者)确实提出了您可能想阅读的有趣评论(我也将其包含在我的回答中)

标签: eclipse ant p2


【解决方案1】:

通过阅读this threadP2 Publisher documentation,它应该在org.eclipse.equinox.launcher_*.jar

仅针对 -jar 参数的 P2 任务示例(此处不是 ant 任务):

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 tasks are described here,以及Eclipse help


OP Anthony43 在 cmets 中添加:

我只想在 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 

Andrew Niefer(PDE/Build、p2 和 Equinox 框架上的 Eclipse 提交者)补充道:

p2 任务需要在 osgi 环境中运行,不能在正常的 ant 运行中运行
这就是您需要使用org.eclipse.ant.core.antRunner 应用程序的原因。
以“java -jar launcher.jar”开头只是调用 eclipse 可执行文件的另一种方法。


martin jakubik 提及:

我希望看到一个可以剪切和粘贴并将所有内容放在一起的命令。
我用的是:

java -jar <eclipse-install-directory>\eclipse\plugins\org.eclipse.equinox.launcher_*.jar -application org.eclipse.ant.core.antRunner. 

请注意,我不知道&lt;targetProductFolder&gt; 是什么,所以我改用&lt;eclipse-install...&gt;

【讨论】:

  • 您好!谢谢你的回答,但是......我只想在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 /home/nboldt/eclipse/workspace-jboss/org.eclipse.dash.common.releng/tools/scripts/partialMirrorFromRepo.xml 无论如何!
  • p2 任务需要在 osgi 环境中运行,不能在正常的 ant 运行中运行。这就是您需要使用 org.eclipse.ant.core.antRunner 应用程序的原因。以“java -jar launcher.jar”开头只是调用 eclipse 可执行文件的另一种方法。
  • 是的,我完全同意,要完成,使用 p2 任务启动 ant 目标,必须在 Equinox 容器中使用 Eclipse 或 antRunner。谢谢 VonC,安东尼
  • 嗨,很好的答案,最终对我有用。我在阅读链接页面时学到了很多东西。但我希望看到一个可以剪切和粘贴并将所有内容放在一起的命令。我使用的是 java -jar \eclipse\plugins\org.eclipse.equinox.launcher_*.jar -application org.eclipse.ant.core.antRunner。请注意,我无法弄清楚 是什么,所以我使用 代替。如果您可以将此添加到您的答案中,我会投票。
【解决方案2】:

我为此创建了一个小型 Ant 宏

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

【讨论】:

  • 加一个用于展示如何从一个 ant 脚本中执行此操作,但我不明白 @antFile 的目的。我们必须在 Eclipse 中指定 antfile 还是 antrunner 为我找到它?我如何知道在哪里可以找到常见任务的 ant 文件?
【解决方案3】:

所有 p2 任务都需要 eclipse 运行时(正如上面提到的 eclipse 帮助中明确说明的那样),所以你肯定需要使用 eclipse。

绕过它的唯一方法是分析 eclipse 代码,提取所需内容并使用它创建自己的构建系统。

【讨论】:

    【解决方案4】:

    只是为了完成Jarek Przygódzki 的示例,这是我的解决方案,使用他的 ant 文件。我不太熟悉使用 ant,所以可能有优化的潜力。 这种方法在没有 GUI 的服务器上无头使用,但我必须安装 eclipse。使用 apt-get 安装不起作用,因此最好手动安装(下载并解压缩)。

    1. 第一个 antfile 组合名称、版本等...
    2. 从第一个 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>   
    

    第二个 Antfile,名为 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>
    

    【讨论】:

      猜你喜欢
      • 2012-04-06
      • 2012-09-30
      • 2011-12-30
      • 2013-12-13
      • 2011-10-05
      • 2011-03-31
      • 1970-01-01
      • 2010-09-22
      • 2013-03-01
      相关资源
      最近更新 更多