<h1>Creating a Cordapp<aclass="headerlink"href="#creating-a-cordapp"title="Permalink to this headline">¶</a></h1>
<p>A Cordapp is an application that runs on the Corda platform using the platform APIs and plugin system. They are self
contained in separate JARs from the node server JAR that are created and distributed.</p>
<divclass="section"id="app-plugins">
<h2>App Plugins<aclass="headerlink"href="#app-plugins"title="Permalink to this headline">¶</a></h2>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">Currently apps are only supported for JVM languages.</p>
</div>
<p>To create an app plugin you must you must extend from <aclass="reference external"href="api/com.r3corda.core.node/-corda-plugin-registry/index.html">CordaPluginRegistry</a>. The JavaDoc contains
specific details of the implementation, but you can extend the server in the following ways:</p>
<olclass="arabic simple">
<li>Required protocols: Specify which protocols will be whitelisted for use in your web APIs.</li>
<p>Services are classes which are constructed after the node has started. It is provided a <aclass="reference external"href="api/com.r3corda.node.services.api/-service-hub-internal/index.html">ServiceHubInternal</a> which
allows a richer API than the <aclass="reference external"href="api/com.r3corda.node.services.api/-service-hub/index.html">ServiceHub</a> exposed to contracts. It enables adding protocols, registering
message handlers and more. The service does not run in a separate thread, so the only entry point to the service is during
construction, where message handlers should be registered and threads started.</p>
</div>
<divclass="section"id="starting-nodes">
<h2>Starting Nodes<aclass="headerlink"href="#starting-nodes"title="Permalink to this headline">¶</a></h2>
<p>To use an app you must also have a node server. To create a node server run the gradle installTemplateNodes task.</p>
<p>This will output the node JAR to <codeclass="docutils literal"><spanclass="pre">build/libs/corda.jar</span></code> and several sample/standard
node setups to <codeclass="docutils literal"><spanclass="pre">build/nodes</span></code>. For now you can use the <codeclass="docutils literal"><spanclass="pre">build/nodes/nodea</span></code> configuration as a template.</p>
<p>Each node server by default must have a <codeclass="docutils literal"><spanclass="pre">node.conf</span></code> file in the current working directory. After first
execution of the node server there will be many other configuration and persistence files created in a node workspace directory. This is specified as the basedir property of the node.conf file, or else can be overidden using <codeclass="docutils literal"><spanclass="pre">--base-directory=<workspace></span></code>.</p>
<pclass="last">Also note that the bootstrapping process of the <codeclass="docutils literal"><spanclass="pre">corda.jar</span></code> unpacks the Corda dependencies into a temporary folder. It is therefore suggested that the CAPSULE_CACHE_DIR environment variable be set before starting the process to control this location.</p>
<h2>Installing Apps<aclass="headerlink"href="#installing-apps"title="Permalink to this headline">¶</a></h2>
<p>Once you have created your app JAR you can install it to a node by adding it to <codeclass="docutils literal"><spanclass="pre"><node_dir>/plugins/</span></code>. In this
case the <codeclass="docutils literal"><spanclass="pre">node_dir</span></code> is the location where your node server’s JAR and configuration file is.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">If the directory does not exist you can create it manually.</p>
</div>
</div>
<divclass="section"id="starting-your-node">
<h2>Starting your Node<aclass="headerlink"href="#starting-your-node"title="Permalink to this headline">¶</a></h2>
<p>Now you have a node server with your app installed, you can run it by navigating to <codeclass="docutils literal"><spanclass="pre"><node_dir></span></code> and running</p>
<blockquote>
<div>java -jar corda.jar</div></blockquote>
<p>The plugin should automatically be registered and the configuration file used.</p>
<divclass="admonition warning">
<pclass="first admonition-title">Warning</p>
<pclass="last">If your working directory is not <codeclass="docutils literal"><spanclass="pre"><node_dir></span></code> your plugins and configuration will not be used.</p>
<p>Otherwise the workspace folder for the node is created based upon the <codeclass="docutils literal"><spanclass="pre">basedir</span></code> property in the <codeclass="docutils literal"><spanclass="pre">node.conf</span></code> file and if this is relative it is applied relative to the current working path.</p>
</div>
<divclass="section"id="debugging-your-node">
<h2>Debugging your Node<aclass="headerlink"href="#debugging-your-node"title="Permalink to this headline">¶</a></h2>
<p>To enable remote debugging of the corda process use a command line such as:</p>
<h2>Viewing persisted state of your Node<aclass="headerlink"href="#viewing-persisted-state-of-your-node"title="Permalink to this headline">¶</a></h2>
<p>To make examining the persisted contract states of your node or the internal node database tables easier, and providing you are
using the default database configuration used for demos, you should be able to connect to the internal node database over
a JDBC connection at the URL that is output to the logs at node start up. That URL will be of the form <codeclass="docutils literal"><spanclass="pre">jdbc:h2:tcp://<host>:<port>/node</span></code>.</p>
<p>The user name and password for the login are as per the node data source configuration.</p>
<p>The name and column layout of the internal node tables is in a state of flux and should not be relied upon to remain static
at the present time, and should certainly be treated as read-only.</p>
</div>
<divclass="section"id="building-against-corda">
<h2>Building Against Corda<aclass="headerlink"href="#building-against-corda"title="Permalink to this headline">¶</a></h2>
<divclass="admonition warning">
<pclass="first admonition-title">Warning</p>
<pclass="last">This feature is subject to rapid change</p>
</div>
<p>Corda now supports publishing to Maven local to build against it. To publish to Maven local run the following in the
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.