如何在Ant中将java项目转换为插件项目?

时间:2015-11-06 18:37:49

标签: java eclipse jenkins ant eclipse-plugin

我目前正在尝试编写一个build.xml,它会将正常的Java项目com.example.normal转换为com.example.plugin.jar

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

这是用于创建jar文件的示例代码段。

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

手动,我可以使用以下步骤创建插件:

  

右键点击项目&gt; Export&gt; Plugin Development&gt; Deployable plug-ins and fragments

换句话说,我只需要使用Ant自动执行此过程。知道怎么办吗?

谢谢!

3 个答案:

答案 0 :(得分:0)

单独使用Ant无法做到这一点。您应该使用 Tycho PDE Build来构建捆绑(插件)JAR。请注意,第谷是现代首选的选择;我不确定PDE Build是否已被主动维护或再次使用。

答案 1 :(得分:0)

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

enter image description here

来自Eclipse Mars文档的

This link详细解释。

答案 2 :(得分:0)

您可以尝试手动编辑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>
相关问题