Scripting Module - XML と Maven のサポート - Mule 4

XML で Mule アプリケーションを手動でコーディングすることもできますが、Anypoint Studio を使用した方が効率的です。

Anypoint Studio の XML エディターまたはテキストエディターから Mule Runtime Engine (Mule) アプリケーションを手動でコーディングする場合、参照ステートメントを XML Mule フローと Apache Maven ​pom.xml​ ファイルの両方に追加することで、アプリケーションでコネクタにアクセスできます。

コネクタを Studio にインストールすると、Studio は自動的に XML コードにコネクタの名前空間およびスキーマの場所を入力します。さらに、​pom.xml​ ファイルに連動関係を追加します。

モジュールの名前空間の追加

次のコードを設定 XML のヘッダーの ​<mule>​ タグ内に貼り付けます。

http://www.mulesoft.org/schema/mule/scripting-module
http://www.mulesoft.org/schema/mule/scripting-module/current/mule-scripting-module.xsd

次の例は、​<mule>​ XML ブロック内に名前空間ステートメントが配置される方法を示しています。

<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:file="http://www.mulesoft.org/schema/mule/file"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
	http://www.mulesoft.org/schema/mule/core/current/mule.xsd
	http://www.mulesoft.org/schema/mule/file
	http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
    http://www.mulesoft.org/schema/mule/scripting
    http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">

POM ファイルの連動関係の追加

Apache Maven ​pom.xml​ ファイルは Anypoint Studio によって生成され、Mule アプリケーションの連動関係が含まれます。Mule アプリケーションを手動でコーディングする場合、次の XML スニペットを ​pom.xml​ ファイルに含めてこのコネクタにアクセスできるようにします:

<dependency>
    <groupId>org.mule.modules</groupId>
    <artifactId>mule-scripting-module</artifactId>
    <version>2.0.0</version>
    <classifier>mule-plugin</classifier>
</dependency>

最新の ​pom.xml​ ファイル情報を取得する手順は、次のとおりです。

  1. Anypoint Exchange​ に移動します。

  2. Exchange で、​[Login (ログイン)]​ をクリックし、Anypoint Platform のユーザー名とパスワードを指定します。

  3. Exchange で、「​Scripting Module​」を検索します。

  4. モジュールを選択します。

  5. 画面の右上付近にある ​[Dependency Snippets (連動関係スニペット)]​ をクリックします。

Scripting Module は実行エンジンを提供していないため、自分で実行エンジンを提供する必要があります。 たとえば、前のバージョンの Scripting Module で提供されている次のエンジンリストを確認してください。

Groovy:

Scripting Module では、Groovy のバージョン 2.4.x がサポートされています。Anypoint Studio では、バージョン 2.4.21 を使用することをお勧めします。
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.4.21</version>
        <classifier>indy</classifier>
    </dependency>

Python:

    <dependency>
        <groupId>org.python</groupId>
        <artifactId>jython-standalone</artifactId>
        <version>2.7.2</version>
    </dependency>

Ruby:

    <dependency>
        <groupId>org.jruby</groupId>
        <artifactId>jruby-core</artifactId>
        <version>9.2.11.1</version>
    </dependency>
    <dependency>
        <groupId>org.jruby</groupId>
        <artifactId>jruby-stdlib</artifactId>
        <version>9.2.11.1</version>
    </dependency>

次のステップ

名前空間および ​pom.xml​ ファイルを完了したら、​​を試すことができます。