2015-11-06 127 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> 
相關問題