Changes

Jump to navigation Jump to search
2,730 bytes added ,  13:28, 8 March 2019
no edit summary
This article is part of the [[Getting Started]] Section. It describes how to run XPath/XQuery code from within the [https://www.jetbrains.com/idea IntelliJ IDEA IDE]. There are currently two XQuery plugins for IntelliJ IDEA on the market:
* The [https://plugins.jetbrains.com/plugin/9757-xquery-support--marklogic-debugger XQuery Support + MarkLogic Debugger] plugin by Grzegorz Ligas.
* The [https://plugins.jetbrains.com/plugin/8612-xquery-intellij-plugin xquery-intellij-plugin] by Reece H. Dunn.
* The [https://plugins.jetbrains.com/plugin/7262-xquery-support XQuery Support] plugin by Grzegorz Ligas.
* '''Note:''' BaseX itself is a highly compliant XQuery 3.1 processor. We strongly encourage you to use the [[Graphical_User_Interface#Text_Editor|XML editor]] integrated into the BaseX GUI to edit and query your XML data!<br/><br/>
=Preparations=
The following steps apply to all operating systemsand both plugins:
* Install either version of IntelliJ IDEA: [https://www.jetbrains.com/idea/#chooseYourEdition the Community or Ultimate edition].
* Create a BaseX database (see [[Databases]]).
=xquery-intellij-plugin= This section focuses on Reece H. Dunn's [https://plugins.jetbrains.com/plugin/8612-xquery-intellij-plugin 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''' [[File:intellij-startbildschirm.png]] * Start IntelliJ IDEA and select ''Configure''→''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''.* You will be prompted to restart IDEA to load the new plugin. '''From the IntelliJ IDEA Menu'''* Select ''Settings'' (Windows)/''Preferences'' (macOS) 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'' (Windows)/''Preferences'' (macOS) 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.:** <code>Implementation = BaseX</code>** <code>Implementation version = BaseX 9.1</code>** <code>Default XQuery version = XQuery 3.1</code>** <code>Dialect for XQuery 3.0 = BaseX</code>** <code>Dialect for XQuery 3.1 = BaseX</code>[[File:Intellij-xquery-settings-2.png‎]]* Click ''Apply'' to store your XQuery settings and then ''OK'' to exit the dialog. ==Querying Your Data== '''Create a New Project'''* To create a new project choose the ''Create new project'' option from the start screen or select ''New''→''Project...'' 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 and click on the ''Finish'' button. '''Customize the XQuery Module'''* Click the ''Add Configuration'' button below the IntelliJ IDEA menu bar.[[File:Intellij-add-configuration.png]]* In the ''Run/Debug Configurations'' dialog, expand the Templates list and choose the ''XQuery Support '' entry.* Click on the three dots {{Code|...}} next to the ''Query Processor'' dropdown box.* In the ''Manage Query Processors'' dialog, click on the {{Code|+ MarkLogic Debugger}} button.* In the ''New Query Processor Instance'' dialog, set the following preferences:** <code>Name = BaseX</code>** <code>Implementation =BaseX</code> (should be preset!)** <code>JAR File = basex/BaseX.jar</code>** <code>Hostname = localhost</code>** <code>Database port = 1984</code>** <code>Username = admin</code>** <code>Password = admin</code>** If you tick the check box ''Create a standalone instance'', the fields ''Hostname'', ''Database port'', ''Username'', and ''Password'' remain empty.[[File:Intellij-new-query-processor.png]]* Click ''OK'' to exit the ''New Query Processor Instance'' dialog.* In the ''Manage Query Processors'' dialog, 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. '''Create a Query File'''* In the project view, create a new XQuery file, either by right-clicking on the project name and choosing ''New''→''File'' or by selecting ''New''→''File'' from the File menu. Enter a file name and click ''OK''.* Type in your query, e.g. <code>db:open("factbook")</code>, and save your file. '''Create a New Configuration'''* Click on the ''Add Configuration'' button once again.* In the ''Run/Debug Configurations'' dialog, click the {{Code|+}} button to create a new configuration based on a template.* Choose 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.[[File:Intellij-xquery-configuration.png]]* Click ''Apply'' and then ''OK'' to close the ''Run/Debug Configurations'' dialog.* Now, the configuration should be set and the green ''Run'' button should be available below the IntelliJ IDEA menu bar.[[File:Intellij-run-button.png]] '''Execute Your Query'''* If the configuration does not run as a standalone instance, make sure that BaseX is up and running.* Click the ''Run'' button to execute your query.
=XQuery Support Plugin= This section focuses on Grzegorz Ligas' [https://plugins.jetbrains.com/plugin/97577262-xquery-support--marklogic-debugger 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===
[[File:intellij-startbildschirm.png]]'''From the Start Screen'''
* Start IntelliJ IDEA and select ''Configure''→''Plugins''.
* In the ''Plugins '' window , select the tab ''Marketplace''.* Type "XQuery Support" into the ''Search plugins in marketplace'' fieldand press Enter.* Click the ''Install'' button below the ''XQuery Support + MarkLogic Debugger'' pluginor click on the ''XQuery Support'' link to get more information on the plugin before installing it.
* You will be prompted to restart IDEA to load the new plugin.
==='''From the IntelliJ IDEA Menu==='''* Select ''Settings'' (Windows)/''Preferences'' in (macOS) from the ''IntelliJ IDEA'' menu.* In the Settings/Preferences window , select ''Plugins''.* In the ''Plugins window '' panel, select the tab ''Marketplace''.* Type "XQuery Support" into the ''Search plugins in marketplace'' fieldand press Enter.* Click the ''Install'' button below the ''XQuery Support + MarkLogic Debugger'' pluginor click on the ''XQuery Support'' link to get more information on the plugin before installing it.
* 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'' (Windows)/''Preferences'' (macOS) either using the ''Configure'' button from on 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 and which XQuery flavor you would like to use.
* Click ''Apply'' to store your XQuery settings.
===Standalone===
* In the ''Settings'' (Windows)/''Preferences '' (macOS) window, expand the ''Languages & Frameworks'' item and select ''XQuery Data Sources''.* Click on the {{Code|+}} 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 {{Code|+}} button below the check box to add the following {{code|jars}} from your BaseX distribution:
** {{Code|basex/BaseX.jar}}
** {{Code|basex/lib/basex-apj-9.1.12.jar}}
** {{Code|basex/lib/basex-xqj-9.0.jar}}
** {{Code|basex/lib/xqj2-0.2.0.jar}}
===Client===
This assumes that you already have a BaseX database named {{code|factbook}}.
* In the ''Settings'' (Windows)/''Preferences '' (macOS) window, expand the ''Languages & Frameworks'' item and select ''XQuery Data Sources''.* Click on the {{Code|+}} 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:
** <code>Host = localhost</code>
** <code>Port = 1984</code>
==Querying Your Data==
* To create a new project, choose the ''Create new project'' option from the start screen or select ''New''→''Project...'' 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 ''New''→''XQuery File'' or by selecting ''New''→''XQuery File'' from the File menu.
* 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'''Create a New Project'''* To create a new project choose the ''Create new project'' option from the start screen or select ''New''→''Project...'' from the ''File'' menu.* In the ''New Project'' dialog, choose ''Empty Project'' from the left-intellij-plugin=hand column and click the ''Next'' button.* Enter a name and location for your project and click on the ''Finish'' button.
This section focuses on Reece H'''Customize the XQuery Module'''* Click the ''Add Configuration'' button below the IntelliJ IDEA menu bar. Dunn's [[httpsFile:Intellij-add-configuration.png]]* In the ''Run//pluginsDebug Configurations'' dialog, expand the Templates list and choose the ''XQuery Main Module'' entry.jetbrains* Click on the ''Configure'' button next to the ''Data Source'' field and either choose the previously configured standalone version (''BaseX (native embedded)'' item) or the client version (''BaseX'' item) from the list.com* Click ''Apply'' and then ''OK'' to close the ''Run/plugin/8612-xquery-intellij-plugin xquery-intellij-plugin]Debug Configurations'' dialog.
==Installation=='''Create a Query File'''* In the project view, create a new XQuery file by right-clicking on the project name and choosing New→XQuery File. Enter a file name, select ''Main Module'' from the ''Kind'' dropdown and click OK.* Type in your query and save your file.[[File:Intellij-query.png]]
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 ''Configure'Create a New Configuration'''* Click on the ''PluginsAdd Configuration''button once again.* In the Plugins window select the tab ''MarketplaceRun/Debug Configurations''dialog, click the {{Code|+}} button to create a new configuration based on a template.* Type Choose the "XQueryMain Module" template you configured earlier.* Enter a name, e.g. " BaseX", into the ''Search plugins in marketplaceName'' field.* Click the The data source should be preset either to "BaseX (native embedded)" or ''Install'' button below ''xquery-intellij-pluginBaseX''depending on your processor configuration.* You will be prompted to restart IDEA to load the new plugin. ===From In the IntelliJ IDEA Menu===* Select ''Settings/PreferencesMain file'' in field, enter the ''IntelliJ IDEA'' menupath to your query file.[[File:Intellij-xquery-configuration2.png]]* In the Settings/Preferences window select Click ''PluginsApply''.* In the Plugins window select the tab and then ''MarketplaceOK''.* Type "XQuery" into to close the ''Search plugins in marketplaceRun/Debug Configurations'' fielddialog.* Click Now, the configuration should be set and the green ''InstallRun'' button should be available below ''xquerythe IntelliJ IDEA menu bar.[[File:Intellij-intellijrun-plugin'' plugin.* You will be prompted to restart IDEA to load the new pluginbutton.png]]
==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, select ''XQuery''.
* Make the choices for your system from the dropdown boxes, e.g.:
** <code>Implementation = BaseX</code>
** <code>Implementation version = BaseX 9.1</code>
** <code>Default XQuery version = XQuery 3.1</code>
** <code>Dialect for XQuery 3.0 = BaseX</code>
** <code>Dialect for XQuery 3.1 = BaseX</code>
* 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 ''New''→''Project...'' 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.
* Expand the Templates list and choose the ''XQuery'' entry.
* In the ''Run/Debug Configurations'' dialog click on the three dots {{Code|...}} next to the ''Query Processor'' dropdown box.
* In the ''Manage Query Processors'' dialog click on the {{Code|+}} button.
* In the ''New Query Processor Instance" dialog, set the following preferences:
** <code>Name = BaseX</code>
** <code>Implementation = BaseX</code> (should be preset!)
** <code>Implementation = BaseX</code>
** <code>JAR File = basex/BaseX.jar</code>
** <code>Hostname = localhost</code>
** <code>Database port = 1984</code>
** <code>Username = admin</code>
** <code>Password = admin</code>
* 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 ''New'Execute Your Query'''XQuery File'' or by selecting ''New''→''XQuery File'' from the File menu.* Type in your query.* Click If 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"configuration does not run as a standalone instance, make sure that BaseX is up and running.* Click the ''Run'' button to execute your query.
administrator, editor
162

edits

Navigation menu