2015-11-06 134 views
1

我目前正在尝试编写一个build.xml,它会将一个正常的java项目com.example.normal转换为com.example.plugin.jar如何将Java项目转换为Ant中的插件项目?

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

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

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

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

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

换句话说,我只需要使用Ant自动执行此过程。任何想法如何继续?

谢谢!

回答

0

这不能单用Ant来完成。您应该使用TychoPDE Build来构建包(插件)JAR。请注意,Tycho是现代首选的选择;我不确定PDE Build甚至会被主动维护或使用。

+0

是的,我知道它可以使用第谷来完成,但对于相对小规模项目的安装过程和Maven和第谷的都似乎使用非常复杂。 – HackCode

+0

Maven是一个简单的安装,而Tycho只是Maven的一个插件(不需要安装)。 Tycho有一点学习曲线,但我敢肯定你会发现做这项工作所需的工作不仅仅是学习Tycho的工作。 –

0

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

enter image description here

This link从Eclipse火星文档详细解释。

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> 
相关问题