Integrating IntelliJ IDEA

From BaseX Documentation
Revision as of 16:09, 24 January 2019 by Sabine Teubner (talk | contribs)
Jump to navigation Jump to search

This article is part of the Getting Started Section. It describes how to run XPath/XQuery code from within the IntelliJ IDEA IDE. There are currently two XQuery plugins for IntelliJ IDEA on the market:

Preparations

The following steps apply to all operating systems:

XQuery Support + MarkLogic Debugger

This section focuses on Grzegorz Ligas' XQuery Support plugin.

Installation

After installing IntelliJ IDEA and BaseX, install the XQuery Support plugin by one of the following methods:

From the Start Screen

 

  • Start IntelliJ IDEA and select ConfigurePlugins.
  • In the Plugins window select the tab Marketplace.
  • Type "XQuery Support" into the Search plugins in marketplace field.
  • Click the Install button below the XQuery Support + MarkLogic Debugger plugin.
  • You will be prompted to restart IDEA to load the new plugin.

From the IntelliJ IDEA Menu

  • Select Settings/Preferences in the IntelliJ IDEA menu.
  • In the Settings/Preferences window select Plugins.
  • In the Plugins window select the tab Marketplace.
  • Type "XQuery Support" into the Search plugins in marketplace field.
  • Click the Install button below the XQuery Support + MarkLogic Debugger plugin.
  • You will be prompted to restart IDEA to load the new plugin.

Setting Up

File Extensions and XQuery Flavor

  • Start IntelliJ IDEA and navigate to Settings/Preferences either using the Configure button from the start screen or the IntelliJ IDEA menu.
  • In the Settings/Preferences window, expand the Languages & Frameworks item, select XQuery and choose which default file extensions ans which XQuery flavor you would like to use.
  • Click Apply to store your XQuery settings.

 

Configuring The Processor

You can set up the plugin as a standalone processor or client.

Standalone

  • In the Settings/Preferences window, expand the Languages & Frameworks item and select XQuery Data Sources.
  • Click on the + button in the middle column, to add a new data source.
  • Select BaseX (native embedded) from the dropdown box.
  • In the right-hand column, check the User defined XQJ Driver check box.
  • Use the + button below the check box to add the following jars from your BaseX distribution:
    • basex/BaseX.jar
    • basex/lib/basex-apj-9.1.1.jar
    • basex/lib/basex-xqj-9.0.jar
    • basex/lib/xqj2-0.2.0.jar
  • Click Apply to store your settings.

Client

This assumes that you already have a BaseX database named factbook.

  • In the Settings/Preferences window, expand the Languages & Frameworks item and select XQuery Data Sources.
  • Click on the + button in the middle column, to add a new data source.
  • Select BaseX from the dropdown box.
  • In the right-hand column, fill in the appropriate connection details; e.g. default values:
    • Host = localhost
    • Port = 1984
    • Database name = factbook
    • Username = admin
    • Password = admin
  • Select Apply, then OK and your BaseX factbook database is ready to query.

 

Querying Your Data

  • To create a new project, choose the Create new project option from the start screen or select NewProject... from the File menu.
  • In the New Project dialog choose Empty Project from the left-hand column and click the Next button.
  • Enter a name and location for your project.
  • In the project view, create a new XQuery file, either by right-clicking on the project name and choosing NewXQuery File or by selecting NewXQuery File from the File menu. Enter a file name and click OK.
  • Type in your query.

 

  • Click the green Run button below the IntelliJ IDEA menu bar.
  • In the Edit Configuration dialog choose one of the two data source from the dropdown box, either "BaseX" or "BaseX (native embedded)". If you select "BaseX", make sure that BaseX is up and running.
  • Click Run to execute your query.

xquery-intellij-plugin

This section focuses on Reece H. Dunn's xquery-intellij-plugin.

Installation

After installing IntelliJ IDEA and BaseX, install the xquery-intellij-plugin by one of the following methods:

From the Start Screen

  • Start IntelliJ IDEA and select ConfigurePlugins.
  • In the Plugins window select the tab Marketplace.
  • Type "XQuery" into the Search plugins in marketplace field.
  • Click the Install button below xquery-intellij-plugin.
  • You will be prompted to restart IDEA to load the new plugin.

From the IntelliJ IDEA Menu

  • Select Settings/Preferences in the IntelliJ IDEA menu.
  • In the Settings/Preferences window select Plugins.
  • In the Plugins window select the tab Marketplace.
  • Type "XQuery" into the Search plugins in marketplace field.
  • Click the Install button below xquery-intellij-plugin plugin.
  • You will be prompted to restart IDEA to load the new plugin.

Configuring The Processor

  • Start IntelliJ IDEA and navigate to Settings/Preferences either using the Configure button from the start screen or the IntelliJ IDEA menu.
  • In the Settings/Preferences window, expand the Languages & Frameworks item and select XQuery.
  • Make the choices for your system from the dropdown boxes, e.g.:
    • Implementation = BaseX
    • Implementation version = BaseX 9.1
    • Default XQuery version = XQuery 3.1
    • Dialect for XQuery 3.0 = BaseX
    • Dialect for XQuery 3.1 = BaseX

 

  • Click Apply to store your XQuery settings and then OK to exit the dialog.

Querying Your Data

  • To create a new project, choose the Create new project option from the start screen or select NewProject... from the File menu.
  • In the New Project dialog choose Empty Project from the left-hand column and click the Next button.
  • Enter a name and location for your project.
  • Click the Add Configuration button below the IntelliJ IDEA menu bar.

 

  • In the Run/Debug Configurations dialog expand the Templates list and choose the XQuery entry.
  • Click on the three dots ... next to the Query Processor dropdown box.
  • In the Manage Query Processors dialog click on the + button.
  • In the New Query Processor Instance" dialog, set the following preferences:
    • Name = BaseX
    • Implementation = BaseX (should be preset!)
    • JAR File = basex/BaseX.jar
    • Hostname = localhost
    • Database port = 1984
    • Username = admin
    • Password = admin

 

  • Click OK to exit the New Query Processor Instance" dialog.
  • In the Manage Query Processors now choose the "BaseX 9.1.1 (BaseX)" entry and click OK.
  • The Query Processor dropdown box in the Run/Debug Configurations dialog should now also display "BaseX 9.1.1 (BaseX)". If not, select it from the dropdown box.
  • Click Apply and then OK to close the Run/Debug Configurations dialog.
  • In the project view, create a new XQuery file, either by right-clicking on the project name and choosing NewFile or by selecting NewFile from the File menu. Enter a file name and click OK.
  • Type in your query.
  • Click on the Add Configuration button once again.
  • In the Run/Debug Configurations dialog click the + button to create a new configuration based on a template.
  • Chose the "XQuery" template you configured earlier.
  • Enter a name, e.g. "BaseX" into the Name field.
  • The query processor should be preset to "BaseX 9.1.1 (BaseX)".
  • In the Script File field enter the path to your query file.

 

  • Click Apply and then OK to close the Run/Debug Configurations dialog.
  • Now, the green Run button should be available below the IntelliJ IDEA menu bar.

 

  • Make sure that BaseX is up and running and click the Run button to execute your query.