LoginSignup
3
3

More than 5 years have passed since last update.

[Eclipseプラグイン開発] プラグインのエクスポート用Antスクリプト

Posted at

目的

  • Eclipse プラグインのエクスポート用のAntスクリプトについてのメモ
  • 覚え書き的 tips
  • Eclipse 4.4~4.5で確認

まとめ

  • Export時に「Options」タブでAntスクリプトを保存する
  • スクリプト名は build.xml 以外にする必要がある
  • いくつか保存されない項目がある
  • JREはワークスペースと同じ環境を使うようにする
  • エクスポートは非同期に実行される

Antスクリプトの作成方法

Eclipseプラグインをプラグイン形式のjarにパッケージする場合、通常はExport機能を使います。

  • 「File」メニューから「Export...」、あるいは
  • プロジェクトを右クリックして「Export...」

しかし、Antスクリプトを用いてエクスポートすることも可能です。

  • まずは通常通りExport機能を実行
  • エクスポートの種類として「Deployable plug-ins and fragments」を選ぶ
  • 各種、必要な設定をする
  • 「Options」タブで「Save as Ant script」にチェックを入れる
  • 保存するAntスクリプトファイル名を指定する。このとき、ファイル名が build.xml だとエラーが出るので、別の名前にしてください( build_plugin.xml とか)。

保存されたスクリプトのファイルパスなどを適当に修正すれば、とりあえずOKです。

Antスクリプトの実行方法

保存・編集したAntスクリプトを実行する際には、ワークスペース(Eclipse本体)と同じJREを使うようにしてください。

具体的には、Run Configuration で「JRE」タブを開き「Run in the sae JRE as the workspace」を選択してください。

Antスクリプトを実行すると、Antのタスクはすぐに終了しますが、少ししたら Eclipse のエクスポートジョブが起動します。
AntからはEclipseのエクスポートジョブをキックしているだけのようです。

保存されない項目

上記方法で、ほとんどの場合問題ないと思います。
しかし、エクスポート時に指定した項目がいくつか(少なくとも1つ)Antスクリプトに保存されないようでした。

具体的にはExport時に「Options」タブで「Allow for binary cycles in target platform」にチェックを入れていても、Antスクリプトに反映されていないようです(他にもあるかもしれませんが)。

プラグイン開発用のプラグイン(PDE)のソースを確認したところ、Antスクリプトは org.eclipse.pde.ui プラグインの中の org.eclipse.pde.internal.ui.wizards.exports.PluginExportWizard で生成しているようですが、確かに保存していないようです。

実際のエクスポート処理の方を見てみたところ、Antスクリプトの pde.exportPlugins 要素に allowBinaryCycles 属性とboolean値( true )を指定すれば上手くいくようです。

build_plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<project default="plugin_export" name="build">
    <!-- プラグインエクスポート用build.xml -->
    <!-- JRE は "Run in the same JRE as the workspace" を選択 -->
    <!-- エクスポート自体は非同期で動作するので注意! -->
    <target name="plugin_export">
        <pde.exportPlugins
            destination="."
            exportSource="false"
            exportType="directory"
            plugins="com.example.plugin"
            allowBinaryCycles="true"
            useJARFormat="true"/>
    </target>
</project>
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3