【问题标题】:How to convert a java project to a plugin project in Ant?如何在 Ant 中将 java 项目转换为插件项目?
【发布时间】:2015-11-06 18:37:48
【问题描述】:

我目前正在尝试编写一个build.xml,它将一个普通的java项目比如com.example.normal转换为com.example.plugin.jar

我有一个基本 build.xml 的代码,它创建了一个源项目的 jar。但通常创建jar 文件与创建插件jar 文件不同。出于这个原因,我需要使用 ant 创建一个plugin jar 文件,而不仅仅是一个不能充当插件的普通 jar 文件。

这是创建jar文件的示例代码sn-p。

<jar destfile="generatedPlugins/com.example.normal.jar">
       <fileset dir="JavaSource/com.example.normal"/>
</jar>

手动,我可以通过以下步骤创建插件:

右键项目>Export>Plugin Development>Deployable plug-ins and fragments.

换句话说,我只需要使用 Ant 自动化这个过程。知道如何进行吗?

谢谢!

【问题讨论】:

    标签: java eclipse jenkins ant eclipse-plugin


    【解决方案1】:

    仅靠 Ant 无法做到这一点。您应该使用 TychoPDE Build 来构建捆绑(插件)JAR。请注意,第谷是现代的首选选择;我不确定 PDE Build 是否得到积极维护或使用。

    【讨论】:

    • 是的,我知道可以使用 Tycho 完成,但是对于相对较小的项目,Maven 和 Tycho 的安装过程和使用似乎非常复杂。
    • Maven 是一个简单的安装,而 Tycho 只是一个 Maven 的插件(无需安装)。第谷有一些学习曲线,但我很确定你会发现完成这项工作所需的工作不仅仅是学习第谷的工作。
    【解决方案2】:

    您可以尝试手动编辑 build.xml,添加类似

    <!-- This builds a .jar file, Assuming you have a set of .class files
         created by some "compile" target. -->
    <target name="build" depends="compile">
    
        <!-- We need to set up class path for any required libraries so that we
             can add it to the manifest file later. -->
        <path id="build.classpath">
            <pathelement location="${lib.location}"/>
        </path>
    
        <!-- Now we convert the class path we just set up to a manifest class
             path - we'll call it manifest.cp. We also need to tell it where our 
             .jar file will be output. -->
        <manifestclasspath property="manifest.cp" jarfile="${jar.output.dir}/filename.jar">
            <!-- We just give it the classpath we set up previously. -->
            <classpath refid="build.classpath"/>
        </manifestclasspath>
    
        <!-- Now we can make the .jar. It needs to know the base directory of
             our compiled .class files. -->
        <jar destfile="${jar.target}/filename.jar" basedir="${class.target}">
            <!-- Set up the manifest file with the name of the main class and
                 the manifest class path we set up earlier. -->
            <manifest>
                <attribute name="Main-Class" value="name of main class"/>
                <attribute name="Class-Path" value="${manifest.cp}"/>
            </manifest>
        </jar>
    
    </target>
    

    【讨论】:

      【解决方案3】:

      您可以通过右键单击项目中的相关清单文件(例如 plugin.xml)并选择 PDE 工具 --> 创建 Ant 构建文件,从 PDE 工具生成 Ant 脚本。

      This link 来自 Eclipse Mars 文档的详细解释。

      【讨论】:

        猜你喜欢
        • 2011-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-21
        • 1970-01-01
        • 1970-01-01
        • 2017-12-07
        相关资源
        最近更新 更多