Eclipse Modeling ToolsでXtextプロジェクトをMavenプロジェクトとして作成する – 【Xtext】
前提
- Eclipse Modeling Toolsインストール済
- Eclipse Xtextプラグインインストール済 「Eclipse Modeling ToolsでXtextプロジェクト作成する – 【Xtext】」参照
- Maven Integration for Eclipse済
mvnプロジェクトとしてXtextプロジェクト作成
「File」-「New」-「Other」を選択します。
「Xtext Project」ー「Next」を選択します。
「Next」を選択して以下の通り設定します。
– ❌ **Eclipse Plug-in**
– ❌ **Web Integration**
– ✔️ **Generic IDE Support**
– ✔️ **Preferred Build System:Maven**
– ✔️ **Build Language Server:Fat Jar**
– ✔️ **Source Layout:Maven/Gradle**
「Finish」を選択すれば完了です。
プロジェクト構成
以下のようなプロジェクト構成になります。MyDsl.xtextを開きます。
適当に編集することによりDSLの編集が行えます。
LSPサーバのランチャー実装(stdio)とpom.xml修正
org.xtext.example.mydsl.ideプロジェクトのLSPサーバのランチャーを新規作成して実装します。org.xtext.example.mydsl.ideパッケージにMyDslServerLauncher.javaを作成します。
package org.xtext.example.mydsl.ide;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.xtext.ide.server.LanguageServerImpl;
import org.eclipse.xtext.ide.server.ServerModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class MyDslServerLauncher {
public static void main(String[] args) throws InterruptedException, IOException, ExecutionException {
Injector injector = Guice.createInjector(new ServerModule());
LanguageServerImpl languageServer = injector.getInstance(LanguageServerImpl.class);
Launcher launcher = Launcher.createLauncher(
languageServer,
LanguageClient.class,
System.in,
System.out
);
languageServer.connect(launcher.getRemoteProxy());
launcher.startListening().get();
}
}
org.xtext.example.mydsl.ideプロジェクトのpom.xmlを1行修正します。
<mainClass>org.xtext.example.mydsl.ide.MyDslServerLauncher</mainClass>
コード生成
org.xtext.example.mydsl.parentプロジェクトを選択して、右クリックから「Run As」-「Maven install」を選択します。
org.xtext.example.mydsl.ide/target配下に以下jarが作成されます。
- org.xtext.example.mydsl.ide-1.0.0-SNAPSHOT.jar(Eclipse(OSGi)環境で使用される jar)
- org.xtext.example.mydsl.ide-1.0.0-SNAPSHOT-ls.jar(fat jarはVS Codeで使用できる)
org.xtext.example.mydsl.ide-1.0.0-SNAPSHOT-ls.jarを使ってLSPを起動し、VS CodeでXtext動作確認が出来るようになります。

KHI入社して退社。今はCONFRAGEで正社員です。関西で140-170/80~120万から受け付けております^^
得意技はJS(ES20xx),Java,AWSの大体のリソースです
コメントはやさしくお願いいたします^^
座右の銘は、「狭き門より入れ」「願わくは、我に七難八苦を与えたまえ」です^^




